Solved

VFP command that shows a directory of subfolders

Posted on 2011-02-19
8
2,467 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 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 42

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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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 42

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 42

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Part Two of the two-part Q&A series with MalwareTech.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

635 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