Results 1 to 7 of 7

Thread: Easy way to get the win temp folder

  1. #1

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261

    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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    2.  
    3. Private Sub Command1_Click()
    4.     Dim strTemp As String
    5.     'Create a buffer
    6.     strTemp = String(100, Chr$(0))
    7.     'Get the temporary path
    8.     GetTempPath 100, strTemp
    9.     'strip the rest of the buffer
    10.     strTemp = Left$(strTemp, InStr(strTemp, Chr$(0)) - 1)
    11.     MsgBox "The default temp path is: " & strTemp
    12. End Sub

  3. #3

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    I thought there was a way of doing it without API calls...
    Obey the dragon thing. Or not. Or possibly just a bit.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  5. #5

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    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.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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:
    1. Const CSIDL_DESKTOP = &H0
    2. Const CSIDL_PROGRAMS = &H2
    3. Const CSIDL_CONTROLS = &H3
    4. Const CSIDL_PRINTERS = &H4
    5. Const CSIDL_PERSONAL = &H5
    6. Const CSIDL_FAVORITES = &H6
    7. Const CSIDL_STARTUP = &H7
    8. Const CSIDL_RECENT = &H8
    9. Const CSIDL_SENDTO = &H9
    10. Const CSIDL_BITBUCKET = &HA
    11. Const CSIDL_STARTMENU = &HB
    12. Const CSIDL_DESKTOPDIRECTORY = &H10
    13. Const CSIDL_DRIVES = &H11
    14. Const CSIDL_NETWORK = &H12
    15. Const CSIDL_NETHOOD = &H13
    16. Const CSIDL_FONTS = &H14
    17. Const CSIDL_TEMPLATES = &H15

  7. #7

    Thread Starter
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    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
  •  



Click Here to Expand Forum to Full Width