Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VFP command that shows a directory of subfolders

Posted on 2011-02-19
8
Medium Priority
?
2,788 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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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…
The decision to migrate to the cloud is not a simple one—many factors, such a cost, ease of use, and ongoing maintenance come into play. The goal is always for cloud platforms to make storage and backups more seamless and effective. Here’s a look at…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

927 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