Your source for ASP-related frequently asked questions and answers! : ASP FAQS : FileSystemObject

Question: How can I get the path of the system temporary folder? Also, how can I get a filename for a temporary file?

Answer: The FileSystemObject provides a function - GetSpecialFolder - that can be used to retrieve the path of the folder Windows has designated as the temporary folder. GetSpecialFolder can also be used to get the Windows folder name and the System folder name (usually C:\WINNT\ and C:\WINNT\System32, respectively). The GetSpecialFolder function has the following definition:


folderspec determines what special folder is returned:
0 - The Windows Folder is returned
1 - The System folder is returned
2 - The Temporary folder is returned

The GetSpecialFolder function returns a Folder object, which contains a number of properties. To simply get the path to the temporary folder, we will use the GetSpecialFolder to return a folder object, and then use the Path property of the Folder object to return the path of the temporary folder.

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'This will return the path to the temporary folder
Response.Write objFSO.GetSpecialFolder(2).Path

Set objFSO = Nothing

Pretty simple, eh? The FileSystemObject also provides a method to generate a temporary file name, in case you need to quickly create a temporary file. This method is GetTempName. To learn more about it, be sure to read the technical docs.

An article on 4Guys - A Quick and Dirty Random Password Generator - demonstrates how to use the GetTempName to create a seemingly random password. Definitely worth a read! Also be sure to check out these technical docs:
GetSpecialFolder technical docs
Folder object properties

Happy Programming!

FAQ posted by Scott Mitchell at 10/7/2000 6:52:33 PM to the FileSystemObject category. This FAQ has been viewed 46,902 times.

Copyright 2018 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers