Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Search a file in a harddisk...
Message
From
25/01/1999 04:34:56
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
25/01/1999 01:23:46
Aaron K. Y. Chu
Health & Care Co. Ltd.
Hong Kong, Hong Kong
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00179711
Message ID:
00179731
Views:
21
>How to search a file in a harddisk for its subdirectories?
>
>LOCFILE() can only locate files in default and 'pathed' directory.
>I need to search all over the harddisk.
>
>Thanks in advance.
>
>Aaron
Aaron,
This is out of the basket. I found two prgs findfile and findfilenew on my disk and I assume "findfilenew" should be better :) Both has those "? start-seconds()" so they might be be still in test version and need some revision.
lparameters startdir, cfilename
start=seconds()
set talk off
local lcCursorName, llRHSExists
lcCursorName = "C_"+sys(2015)
dimension aTree[1,2]
aTree[1,1] = startdir
aTree[1,2] = ""
=gettree(startDir, @aTree)
? seconds()-start
create cursor filelist ;
	(directory m,filename c(40), ;
	filesize i,filedate d,filetime c(8),fileattr c(5))
set defa to (startdir)
for ix = 1 to alen(aTree,1)
	=checkfile(aTree[ix,1],cFileName)
endfor
? seconds()-start
select filelist
browse
return

function gettree
lparameters tcPath, taTree && Start path, array to insert
local lcTopDir,ix
lcTopDir = sys(5)+curdir()
set defa to (tcPath)
lcCurdir = sys(5)+curdir()
=getsubdirs(lcCurdir, @taTree)
set default to (lcTopDir)
=asort(taTree,1,-1,1) && Sort descending - in case this is a removedir operation
for ix =1 to alen(taTree,1)
	if  !empty(chrtran(taTree[ix,2],"AD.",""))
		return .t.  && Hidden or system dir exists
	endif
endfor		
return .f.

function getsubdirs
lparameters tcPath, taTree
local lcCurDir, lnSubDirs, ix
local array laDirs[1]
lnSubdirs=adir(laDirs,tcPath+"*.*","HD")
for ix = 1 to lnSubDirs
    if laDirs[ix,1]#"." and "D"$laDirs[ix,5]
	    dimension taTree[alen(taTree,1)+1,2]
		taTree[alen(taTree,1),1] = tcPath+laDirs[ix,1]
		taTree[alen(taTree,1),2] = laDirs[ix,5]
	   	=getsubdirs(tcPath+laDirs[ix,1]+"\", @taTree)
    endif
endfor    


***************************************************************************
* CHECKFILE : CHECK cFileName in cDirectory and insert into cursor filelist
***************************************************************************
function checkfile
lparameters cDirectory,cFileName
private aDirectory, ix
nFileCnt = adir(aDirectory,cDirectory+iif(right(cDirectory,1)#"\","\","")+cFilename)
if  nFilecnt > 0
	for ix=1 to alen(aDirectory,1)
		insert into filelist values ;
		(cDirectory,aDirectory[ix,1],;
		aDirectory[ix,2],aDirectory[ix,3],;
		aDirectory[ix,4],aDirectory[ix,5])
	endfor
endif
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform