Referring to %TEMP% in vbscript

L

Long Nguyen

Hi

In vbscript how can I refer to the variable %TEMP% on the PC?

Basically I want to create a new file in a directory on PC pointed to by the
%TEMP% variable. However the code below does not work:

Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = "%TEMP%\myfile.txt"
Set tf = fso.CreateTextFile(FileName, True)

If I use the file name "C:\myfile.txt" it works fine.

Thanks
Long
 
N

Natarajan

Hi Long,

Use the following code instead :

sub test()
Dim fso, tempfile
Set fso = CreateObject("Scripting.FileSystemObject")

Dim tfolder, tname, tfile
Const TemporaryFolder = 2
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
msgbox tfolder

end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top