Solved

VFP command that shows a directory of subfolders

Posted on 2011-02-19
8
2,074 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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
 
LVL 4

Author Closing Comment

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

Thanks all,
jr
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:CaptainCyril
Comment Utility
Welcome!
0
 
LVL 41

Expert Comment

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

Author Comment

by:jruhe
Comment Utility
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
Comment Utility
That's OK, I also agree ADIR is better solution.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now