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