Hi David,
 
What you needed was to expand the contens of the temp dir name again,
because it contained an environment variable (the part surrounded with
percent signs), which was also originally the what you did to the %temp%
environment variable.
 
Below are several different ways I've picked up from others to generate
random file names, or place a file name of your choosing in the temporary
dir:
 
' this one puts the name of your choosing into the temp dir
set oShell = createObject("wScript.shell")
tmpFileName = oShell.ExpandEnvironmentStrings("%temp%") & "\myTemp.tmp"
 
' and so does this one
Set SO_Env = SharedObjects("com.GWMicro.GWToolkit.Env", 0)
tmpFileName = SO_Env("%temp%") & "\myTemp.tmp"
    
' this one actually generates the random file name which it puts in the temp
dir
Set oSystem =CreateObject("Scripting.FileSystemObject")
const tempDirName=2
tmpFileName =  oSystem.GetSpecialFolder(tempDirName).path & "\" &
oSystem.GetTempName()
 
 



 hth,
 
Chip
 
 
  _____  

From: David [mailto:[email protected]] 
Sent: Monday, June 25, 2012 2:44 AM
To: [email protected]
Subject: Creating temporary files?


Listers,
Does anyone here happen to have a simple snip-it code, for the following
scenario? Or any good suggestions?
 
I have an app, that creates a temporary file for a certain task. The
creation of the file has worked fine so far. But since this is only a
temporary file, I had hoped to find a way of storing it in the Temporary
folder on the computer. That is, the folder that is defined in the
environment variable as either "tmp" or "temp", in Windows itself. 
 
I did a bit of research on the net, and found a way to retrieve the contents
of the Temp variable. Here is that code:
 
 Dim Shell: Set Shell = CreateObject( "WScript.Shell")
 Dim Environment: Set Environment = Shell.Environment( "System")
    Dim Tmp: Tmp = Environment( "Temp")
 
The code works fine, and returns the contents of the variable. Problem is,
that it returns things like:
    %systemroot%\Temp
. Now trying a command like:
    Dim FSO: Set FSO = CreateObject( "Scripting.FileSystemObject" )
    Dim F: Set F = FSO.OpenTexstFile( Tmp &"\MyFile.tmp", 2, True)
, I get an error thrown at me, telling that the path is invalid. My guess
is, that the OpenTextFile does not like the %SystemRoot% part of the created
filename.
 
Reason why I tried to get hold of the Temp variable of the OS, is that I
then could have the file stored in the temporary folder, no matter which
machine the app was running on. Is there some kind of property or method,
that will handle the expansion of the %systemroot% into a valid path? We
migh even think of situations where the part between the two percent-signs
could be anythhing else, depending on the computer configuration. 
 
Hope all of this makes any sense. Any good workaround here?
 
Thanks,
 

Reply via email to