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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

path not found - default temporary files directory in compiled exe

Status
Not open for further replies.

vfpgolfer

Programmer
Oct 16, 2004
76
US
We are using vfp8 and occassionally are getting path errors where when exiting a program (compiled exe) will get things like

c:\windows\temp\testprg.fxp not found

This only happens on machines that don't have a c:\windows\temp directory.

Our VFP settings (in tools options) have temporary files set to c:\windows\temp.

Is there a way to establish a default temporary files directory in a compiled exe?
 
There are ways to set a default temp directory, but you will run into the same problem if the directory does not exist. Therefore, I recommend checking to see if the temp directory exist at startup and create it if it does not exist.

* sample code.
Code:
pcTemp = "C:\windows\temp\"
IF NOT directory(pcTemp)
	MD (pcTemp)
ENDIF

If it helps, here is how I handle it. I create the temp directory as a subdirectory off the main app. In other words, the app widget would look like this.

widget
\data
\graphics
\temp
\etc...

I try to cleanup temp files when they are no longer in use, but to be safe I include cleanup code to do this as well. If the cleanup code is unable to delete the file, it is most likely because the file is in use by another and that's okay because we don't want to delete it in that instance. It will be deleted when the other user exits the program.


* sample cleanup code
Code:
* Just in case we left some temp files let's clean them up.
LOCAL ARRAY laTempFiles[1]
lcTempFiles = ADDBS(pcTemp) + "*.*"
lnTempFileCount = adir(laTempFiles,'&lcTempFiles')

IF lnTempFileCount > 0
 ON ERROR lcX = ""
 SET SAFETY OFF
	
 * Attempt to delete any temp files.  
 * There shouldn't be any, 
 * or if there are they should be in use by another  
 * user,  in which case we don't want to delete them.
 *
 * The ON ERROR lcx = "" combined with the 
 * SET SAFETY will handle this okay.
	
 FOR lni = 1 TO lnTempFileCount 
  lcTempFiles = ADDBS(goApp.tempDir) + ALLTRIM(laTempFiles[lni,1])
  DELETE FILE (lcTempFiles)
 ENDFOR
ENDIF

One final note, for demonstration purposes I used a public variable to hold the temp directory name. In real life, I use a property (tempDir) off my global object to hold this information and that frees up one public variable.



Jim Osieczonek
Delta Business Group, LLC
 
Vfpgolfer,

Have you got code in your close-down processing that explicitly references the user's temporary directory -- explicitly deleting files from that directory, for example?

If so, use SYS(2023) to find the path to that directory. Use that in place of a hard-coded path.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks for the help Jim & Mike - I decided last night that I was going to create the temp directory so thanks Jim. RE referencing the temp directory - no we don't - it seems to only occur if compiled by Windows XP Professional. However to be safe, I am going to create c:\windows\temp (if possible as some installations may not even have c:). If we find out anything more I will update this post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top