Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current temporary directory path in VBScript?

Tags:

The VB trick to get the path of the current temporary directory:

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long 

fails in VBScript. So?

like image 740
Fabien Avatar asked Jan 08 '09 14:01

Fabien


3 Answers

WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)

It took me a while to find it on Google. So for the next one looking for the same as me...

like image 193
Fabien Avatar answered Oct 11 '22 13:10

Fabien


Const WindowsFolder = 0

Const SystemFolder = 1

Const TemporaryFolder = 2

Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")

Dim tempFolder: tempFolder = fso.GetSpecialFolder(TemporaryFolder)
like image 41
AnthonyWJones Avatar answered Oct 11 '22 14:10

AnthonyWJones


Another possibility:

CreateObject("WScript.Shell").ExpandEnvironmentStrings("%Temp%")
like image 27
Fionnuala Avatar answered Oct 11 '22 13:10

Fionnuala