Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find Files by Program
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00484302
Message ID:
00484317
Views:
14
>>I need to made a program that find a Table (dbf) in a computer, i don´t know path or drive.
>>
>>Some Idea where could i begin ?
>>
>>Im reading about windows API but ?
>>
>>Thanks and Regards
>
>Hi Guillermo,
>
>I've just found this program on my computer. Unfortunately, it doesn't contain author info, so I don't know, who should receive the credit for this.

Judging by style only, I may guess, this code belongs to Mike Helland. Correct me, if I'm wrong :)

>
>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
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform