Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VFP command that shows a directory of subfolders

Posted on 2011-02-19
8
Medium Priority
?
2,648 Views
Last Modified: 2012-08-14
Is there a VFP command that shows/collects a directory of subfolders?  Let's say I have a folder called "Reports" and subfolders called Invoice Reports, Suncoast Clients, and Suncoast Projects.  ADIR doesn't look like it shows directories.  The RUN dir *. > dir.txt works OK but it shows the 8-character equivalent (so for the above, I'd see INVOIC~1, SUNCOA~1 and SUNCOA~2.

I'm using VFP8.

Any ideas?

Thanks,
jr
0
Comment
Question by:jruhe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 27

Accepted Solution

by:
CaptainCyril earned 1000 total points
ID: 34933493
cDirectory is the initial directory
cExtensions contains the desired extensions you are looking for separated by "|"

PROCEDURE ScanDirectory
LPARAMETERS cDirectory, cExtensions, lRelativeDirs
LOCAL nFiles, nFile, i, nRecno, cDirectory1
IF EMPTY(cDirectory)
	cDirectory = SYS(5) + SYS(2003)
ENDIF
cDirectory1 = cDirectory
IF RIGHT(cDirectory1,1) <> '\'
	cDirectory1 = ADDBS(cDirectory1)
ENDIF
CREATE CURSOR tmpfilenames (directory M, filename M, dir L, scanned L, size N(10), date D, selected L, order C(250))
APPEND BLANK
REPLACE directory WITH cDirectory,;
		dir WITH .t.
SCAN FOR dir AND NOT scanned
	cDirectory = ADDBS(ALLTRIM(tmpfilenames.directory)) + ALLTRIM(tmpfilenames.filename)
	REPLACE scanned WITH .t.
	nFiles = ADIR(aDirectory,cDirectory + '\*.*','D')
	nRecno = RECNO()
	FOR nFile = 1 TO nFiles
		IF aDirectory(nFile,1) = '.' OR aDirectory(nFile,1) = '..'
			LOOP
		ENDIF
		APPEND BLANK
		IF 'D' $ aDirectory(nFile,5)
			REPLACE directory WITH cDirectory,;
					filename WITH aDirectory(nFile,1),;
					date WITH aDirectory(nFile,3),;
					dir WITH .t.
		ELSE
			REPLACE directory WITH cDirectory,;
					filename WITH aDirectory(nFile,1),;
					size WITH aDirectory(nFile,2) ,;
					date WITH aDirectory(nFile,3)
		ENDIF
	ENDFOR
	GOTO nRecno
ENDSCAN
IF lRelativeDirs
	REPLACE ALL directory WITH STRTRAN(directory,cDirectory1,'')
ENDIF
REPLACE ALL order WITH PADR(LEFT(directory,125),125) + PADR(LEFT(filename,125),125)
IF EMPTY(cExtensions)
	SELECT *;
		FROM tmpfilenames;
		ORDER BY order;
		WHERE selected;
		INTO CURSOR tmpfilenames
ELSE
	FOR i = 1 TO OCCURS('|',cExtensions)+1
		REPLACE selected WITH .T. FOR NOT dir AND ('.' + LOWER(extract(cExtensions,'|',i)) $ LOWER(filename))
	ENDFOR
	SELECT *;
		FROM tmpfilenames;
		ORDER BY order;
		WHERE selected;
		INTO CURSOR tmpfilenames
ENDIF

Open in new window

0
 
LVL 12

Assisted Solution

by:jrbbldr
jrbbldr earned 1000 total points
ID: 34933536
"ADIR doesn't look like it shows directories."

ADIR() CAN show directories if the appropriate option is used.  
Example:
   =ADIR(aryDir,"c:\Reports\*.*","D")

The 5th returned element/column of the returned array will have a "D" in it for the Directories.

Look into your VFP Help for  ADIR()

Good Luck


0
 
LVL 43

Expert Comment

by:pcelba
ID: 34934984
Just FYI, the RUN dir *. > dir.txt  displays 8.3 format when you are using COMMAND.COM in DOS mode. CMD.EXE always returns long file name format.

You may also use switches /N or /X in DIR command.

BTW, do you use FOXRUN.PIF to invoke DOS prompt?
0
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
LVL 4

Author Closing Comment

by:jruhe
ID: 34951291
Perfect--that's just what I needed. (pcelba--I was running the VFP RUN command, not the DOS prompt)

Thanks all,
jr
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34951308
Welcome!
0
 
LVL 43

Expert Comment

by:pcelba
ID: 34951362
Yes,  VFP RUN command can use either COMMAND.COM or CMD.EXE. It depends on your decision.
0
 
LVL 4

Author Comment

by:jruhe
ID: 34960791
OHHHH.  OK I got it.  I liked ADIR anyway b/c I didn't really want to deal with that text file.  Thanks though pcelba--I'll remember that for next time :-)
0
 
LVL 43

Expert Comment

by:pcelba
ID: 34961252
That's OK, I also agree ADIR is better solution.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Read on to get a few ideas on how to promote your next corporate event.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question