|
-
Mar 10th, 2002, 06:47 AM
#1
Thread Starter
Hyperactive Member
Easy way to get the win temp folder
Is there an easy way to get the windows temp folder?
I believe it had something to do with the getspecialfolder command, but I can't figure it out..
Obey the dragon thing. Or not. Or possibly just a bit.
-
Mar 10th, 2002, 07:29 AM
#2
VB Code:
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Command1_Click()
Dim strTemp As String
'Create a buffer
strTemp = String(100, Chr$(0))
'Get the temporary path
GetTempPath 100, strTemp
'strip the rest of the buffer
strTemp = Left$(strTemp, InStr(strTemp, Chr$(0)) - 1)
MsgBox "The default temp path is: " & strTemp
End Sub
-
Mar 10th, 2002, 07:34 AM
#3
Thread Starter
Hyperactive Member
I thought there was a way of doing it without API calls...
Obey the dragon thing. Or not. Or possibly just a bit.
-
Mar 10th, 2002, 07:37 AM
#4
Well, if you have an aversion to using APIs I guess you could iterate through all folders on the hard drive until you found one called Temp. I've no idea how to do this without using APIs, but I suspect that if you didn't mind writing a few miles of code, you could find a way.
-
Mar 10th, 2002, 07:44 AM
#5
Thread Starter
Hyperactive Member
You're right, I should use the APi, but I prefer to use none API code. And there could be more then one temp folder on someone's HDD...
Obey the dragon thing. Or not. Or possibly just a bit.
-
Mar 10th, 2002, 07:55 AM
#6
Some call certainly make, on their own, a Temp folder, and that API is not going to return its location. That API is specifically designed to return the location of the Temp folder that is created, by default, when the OS is installed. Its job is to located the Windows Temp folder.
Since you have no way of knowing whether someone has created their own Temp folder, it would seem to me that the best, and safest way to go, would be to use their Windows Temp.
There are, on the other hand, always alternatives. Thats one of the cool things about this forum. Someone will generally come up with an option that hadn't been considered. It isn't always a viable option, but options are nice to have.
What are you lookin' to do with the Temp folder? Maybe you could use something else. There are a bunch of the SpecialFolder APIs that might do something for you. The constants, i.e., folders you can get the path to, for the SHGetSpecialFolderLocation API are as follows. Notice Temp is not one of them. I suspect that is because you can use the API that I gave you to do that, so Temp was not included with the SpecialFolders API was written. Mayone one of these would be better suited to whatever it is that you need done (then again, maybe not, but like I said, options are always nice to have).
VB Code:
Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15
-
Mar 10th, 2002, 09:08 AM
#7
Thread Starter
Hyperactive Member
I just wanna use the temp what it was made for: to temp. store a file.
The win temp seems the most logical place to do this...
thx 4 the list btw, I'm sure It'll come in handy some day.
Obey the dragon thing. Or not. Or possibly just a bit.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|