>procedure FILEFIND >* WARNING: If the user has a directory structure 32+ levels deep, >* this program will crash. >* This procedure will recursively search a specified directory and >* its subdirectories for a particular file and if found return the >* location from the root directory. If the file is not found, the >* message "FILE NOT FOUND!" will be displayed. Wildcard characters >* are not supported. >* Example of how to call this function is : >* TempVariable=FileFind("Customer.dbf","C:") > >lparameters pcFile, CUR_DIR >wait window nowait 'Searching file '+ pcFile >filefound = " " >if right((CUR_DIR),1) = "\" > CUR_DIR=substr(CUR_DIR,1,len(CUR_DIR)-1) >endif >=filesrch(pcFile,CUR_DIR) >if empty(filefound) > filefound = "FILE NOT FOUND!" >endif >wait clear >return upper(filefound) >****************************************************** >function filesrch >* >* This is the recursive part of the program. This function will >* search the specified directory and call itself again if needed to >* search a subdirectory. > >parameter FILENAME, curdir >private FILENAME, curdir, temp_dir, i, j && Private variables needed >* curdir is the current directory. && for recursion to work. >* filename is the file being searched for. >dimension temp_dir(1,1) >temp_dir(1,1)=" " >=adir(temp_dir,curdir+"\"+FILENAME) >if ascan(temp_dir,upper(FILENAME)) != 0 && Search current directory > filefound=curdir + "\"+ upper(FILENAME) > return to FILEFIND && IF file found, end program >endif >=adir(temp_dir,curdir+"\*.","D") && Get subdirectories >if temp_dir(1,1) != " " and filefound =" "&& Search subdirectories > if temp_dir(1,1)="." && Look at first subdirectory > if alen(temp_dir,1)=2 && Possibly no subdirectories > return > endif > i=3 > else > i=1 > endif > for j = i to alen(temp_dir,1) && Start searching subdirectories > curdir=curdir+"\"+temp_dir(j,1) > =filesrch(FILENAME,curdir) && Recursive call > curdir=substr(curdir,1,rat("\",curdir)-1) > endfor >endif >return