Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locate a file in HDD

Status
Not open for further replies.

Ashr

Programmer
Apr 19, 2005
46
HU
I m using this command
Code:
tmp=locfile('d:\' + alltrim(prd) + '.bmp')
, I use this command to see if a file exsist on a HDD or not , if the file exsist I recive back the full path of the file , the problem , when file doesn't exsist a dialog is open to find the file manualy , how can I avoid this dialog, my only perpase is when file exist (picture file) I append him to a general field in the table.

Thank's
 
In addition the LOCFILE command doesn't search subfolders as I sow , maybe there is another command to search a folder including his subfolder to see if file exsist there or not.

Thank's
 
Use the FILE() function.


So a example command would be

tmp=file('d:\' + alltrim(prd) + '.bmp')

tmp would be either .T. or .F.



B"H
Brak


If this helps don't forget to give a purple star!
 
Thank's Brak , the problem with File() & with locfile() both of them r not looking in the subfolder of the location like "d:\" have some subfolder , the file exsist in one of the subfolders but none of those command find him.
The locfile() is some better , result give the full path of file unlike file() which exsist or not.

 
But the file() will not give you a dialog box if the file isn't found, which was your original question.

"the problem , when file doesn't exsist a dialog is open to find the file manualy , how can I avoid this dialog,"

So there is the answer - file(). :)
 
If you do not have ANY idea where the file may be on the HDD, you will have to use FILE() within a routine which will first identify the sub-directories, and then look within each of them.

For something like
"tmp = FILE('d:\' + alltrim(prd) + '.bmp')"

You will first need to identify the sub-directories for drive D:
Code:
DIMENSION arySubDir
mnSubDirCnt = FILE(arySubDir,'D:\*.*',"D")

Look in your Foxpro Help file for FILE() and you will see how to use the "D" option to capture the sub-directory names.

Now the array arySubDir contains the sub-directory names for drive D: and the variable mnSubDirCnt will contain the number of sub-directories found.

With that information you can now create a FOR/ENDFOR loop to look within each sub-directory
Code:
FOR Cntr = 1 TO mnSubDirCnt
   mcSubDirName = arySubDir(Cntr,1)
   IF FILE('d:\' + mcSubDirName + "\" + alltrim(prd) + '.bmp')
       * --- File Found ---
   ELSE
       * --- File Not Found ---
   ENDIF
ENDFOR

The code above only searches one sub-directory, but by modifying the code, you can do this type of searching to whatever sub-directory depth you need.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top