Solved

VFP command that shows a directory of subfolders

Posted on 2011-02-19
8
2,204 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 250 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 250 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 41

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 41

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 41

Expert Comment

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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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