Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Find a File
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00458321
Message ID:
00460422
Views:
10
>I want to know how to find a file on the disk, for example if I want to search for the file "calc.exe", i'd like to return the full path of this file.

Here is some code I posted last year, HTH:
lparam tcDir, lcFileName

*Make sure we have a directory to loop through
if type('tcDir') <> 'C' or not directory(tcDir)
	return
endif

*Set up the variables we'll need
local lnFiles, laFiles[1], lnI, lcDir
lcDir		= iif(tcDir = "\" or ":" $ tcDir, ;
	addbs(tcDir), fullpath(addbs(tcDir)))
wait window nowait lcDir

*Loop through every file and driectory
lnFiles = adir(laFiles, lcDir + '*', 'D')
for lnI = 1 to lnFiles

	do case
		
		*Ignore these two
		case inlist(laFiles[lnI, 1], '.', '..')
			loop
		
		*Recurse for every directory
		case 'D' $ laFiles[lnI, 5]
			findfile(lcDir + laFiles[lnI, 1], lcFileName)

		otherwise
			lnTotalFiles = lnTotalFiles + 1
			if laFiles[lnI, 1] = upper(lcFileName)
				lnFoundFiles = lnFoundFiles + 1
			endif
	endcase

endfor
Previous
Reply
Map
View

Click here to load this message in the networking platform