Programmatically find path to temp folder.

This is a discussion on Programmatically find path to temp folder. within the Windows Programming forums, part of the Platform Specific Boards category; I know that I shouldn't hard code directories into my program. So I need to be pointed in the right ...

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Question Programmatically find path to temp folder.

    I know that I shouldn't hard code directories into my program. So I need to be pointed in the right direction.

    What API should I use to find the path to a computers temporary folder on a system? I thought there might be a way to look up the systems 'enviroment variables', but Google doesn't seem to be much help here.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    The GetTempPath function retrieves the path of the directory designated for temporary files. This function supersedes the GetTempDrive function.

    DWORD GetTempPath(

    DWORD nBufferLength, // size, in characters, of the buffer
    LPTSTR lpBuffer // address of buffer for temp. path
    );
    Parameters

    nBufferLength

    Specifies the size, in characters, of the string buffer identified by lpBuffer.

    lpBuffer

    Points to a string buffer that receives the null-terminated string specifying the temporary file path.

    Return Values

    If the function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. If the return value is greater than nBufferLength, the return value is the size of the buffer required to hold the path.
    If the function fails, the return value is zero. To get extended error information, call GetLastError.

    Remarks

    The GetTempPath function gets the temporary file path as follows:

    1. The path specified by the TMP environment variable.
    2. The path specified by the TEMP environment variable, if TMP is not defined.
    3. The current directory, if both TMP and TEMP are not defined.

  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Thanks for the quick reply!

    Wow, thanks for the quick response. This is exactly what I need.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Part 2
    By Nish in forum C Programming
    Replies: 18
    Last Post: 03-09-2005, 04:05 PM
  2. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 08:28 AM
  3. can .exe find the path to a file?
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 06-12-2002, 01:08 PM
  4. Won't Return pointer, i can't find why...
    By ss3x in forum C++ Programming
    Replies: 2
    Last Post: 02-28-2002, 07:50 PM
  5. C++ programmers, this newbie need help
    By incognito in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 02:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21