Temporary Filenames using Windows API Calls 
Author Message
 Temporary Filenames using Windows API Calls

Could someone tell me how to make a temporary file like Windows does in the
TEMP directory. I found an API call "GetTempFileName", I can't seem to get
it to work though. It creates the "temp" file in the /windows/temp directory
but I can't seem to get the filename that was assigned by the
"GetTempFilename" function. Any help would be appresiated greatly!

Kent D. Behrens



Sat, 11 Oct 1997 03:00:00 GMT  
 Temporary Filenames using Windows API Calls

Quote:

>Could someone tell me how to make a temporary file like Windows does in the
>TEMP directory. I found an API call "GetTempFileName", I can't seem to get
>it to work though. It creates the "temp" file in the /windows/temp directory
>but I can't seem to get the filename that was assigned by the
>"GetTempFilename" function. Any help would be appresiated greatly!

This function puts the new filename in a buffer you provide. Before the CALL,
initialize the buffer to SPACE$(80) or so.

Quote:
>Kent D. Behrens


Murray Alexander
City of Vancouver

"Do it right, or do it over. Which do you prefer?" - me



Sat, 11 Oct 1997 03:00:00 GMT  
 Temporary Filenames using Windows API Calls

Quote:

> Could someone tell me how to make a temporary file like Windows does in the
> TEMP directory. I found an API call "GetTempFileName", I can't seem to get
> it to work though. It creates the "temp" file in the /windows/temp directory
> but I can't seem to get the filename that was assigned by the
> "GetTempFilename" function. Any help would be appresiated greatly!

It should work. Have you declared the function right? (You can
find it in the Win31api.hlp file

Declare Function GetTempFileName Lib "Kernel" \
  (ByVal Drive As Integer, ByVal Prefix As String, ByVal Uniq As Integer, \
   ByVal TempFileName As String) As Integer

Arguments are:

   Drive         The Drive to put the temporary file on. If 0 Windows
                 will use the TEMP variable.
   Prefix        Set it to a string you would like to use as a prefix
                 (1-3 chars and NUL terminated)
   Uniq          If 0 instructs Windows to ensure a uniq name, otherwise
                 Windows will use the value of Uniq as the number.
   TempFileName  Name of file created

Remember to create the space for TempFileName before the call,
e g TempFileName = string$(255) and to NUL terminate the prefix
if you are using it.

Hope this will help!

/Fredrik



Mon, 13 Oct 1997 03:00:00 GMT  
 Temporary Filenames using Windows API Calls

Quote:

>Could someone tell me how to make a temporary file like Windows does in the
>TEMP directory. I found an API call "GetTempFileName", I can't seem to get
>it to work though. It creates the "temp" file in the /windows/temp directory
>but I can't seem to get the filename that was assigned by the
>"GetTempFilename" function. Any help would be appresiated greatly!

Try thi sit works for me...

Const TF_FORCEDRIVE = &H80  
'Drive is the first character of the path...
sDrive = UCase(Left(sPath, 1))
'Force drive we want to be used...
nDrive = Asc(sDrive) + TF_FORCEDRIVE
nUnique = 0
'Change current directory on specified drive to config file value...
ChDir sPath
'Call Windows API function...
nRtn = GetTempFileName(nDrive, sPrefix, nUnique, sTempFileName)
'Strip off the '\0'
sTempFileName = Left(sTempFileName, InStr(sTempFileName, Chr(0)) - 1)
'Strip off the drive...
sNewFileName = Trim(Right(sTempFileName, Len(sTempFileName) - 2))

PZ


Calgary AB



Mon, 13 Oct 1997 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB4: SetParent() API call has temporary effect

2. Windows API Calls using VBscript

3. Problem using SetKeyboardState API call on Windows XP Pro

4. How to broadcast Messages using Windows API Calls?

5. Modal Common Dialog Boxes using Windows API Calls

6. API Call for Filename

7. Windows API call to set windows colors (HELP Please)

8. API-Call to convert long filename to 8.3???

9. API call to get long filenames???!

10. Long filenames ans API calls, grmpf...

11. What API-call returns filenames -length -dates?

12. ??? Win32 API call to expand filename

 

 
Powered by phpBB® Forum Software