Thread: Clean Windows Temp folder and the User Temp folder?

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    42

    Clean Windows Temp folder and the User Temp folder?

    Hi everyone,

    Is there any function that can delete the files located in the windows Temp Directory and the user Temp Directory ( from Windows 98 up to Windows Vista ) ?

    If there is no such function, how can i get the path to the windows Temp Directory and the user Temp Directory under Windows 98?



    Best regards

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, there is no such API.
    However, you can get the temp directory using GetTempPath API.
    Windows\Temp folder is not a temp folder at all. It was used before I think, but not anymore. But applications still puts junk there. There's no API to will return that path, so you can use the GetWindowsDirectory API and add \Temp to find that path.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Thanks for quick reply.

    But i think that (GetTempPath and GetWindowsDirectory ) work only under Windows Vista, Windows XP, or Windows 2000 Professional ! Am i wrong?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    GetWindowsDirectory works on Windows 95+, but GetTempPath only works on Windows 2000+. The other way would be to check the tmp or temp environment variables.
    You can get an environment variable with GetEnvironmentVariable. Works on 95+.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Quote Originally Posted by Elysia View Post
    GetWindowsDirectory works on Windows 95+, but GetTempPath only works on Windows 2000+. The other way would be to check the tmp or temp environment variables.
    You can get an environment variable with GetEnvironmentVariable. Works on 95+.
    Many thanks, i will try it and reply later.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    O.K i have tested (GetWindowsDirectory and GetTempPath) out on Windows 98 and both of them returned error code (120) which means:


    ERROR_CALL_NOT_IMPLEMENTED This function is not supported on this system.
    120
    0x78
    EDIT:

    Oops! i will test GetEnvironmentVariable and reply again. Sorry.
    Last edited by patrick22; 01-27-2008 at 11:19 AM.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What's the code?
    Are you using unicode?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Quote Originally Posted by Elysia View Post
    Are you using unicode?
    OMG! You're Right. I made An "Unforgivable Mistake" Attachment 7780

    All of the previous functions works on Windows 98 just fine. And here is the code to test it :
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <string>
    #include <iostream>
    
    #define BUFSIZE 4096
    #define VARNAME TEXT("tmp")
    
    int main()
    {
        DWORD dwRetVal;
    	DWORD dwRet, dwErr;
        DWORD dwBufSize=BUFSIZE;
    
    	CHAR envtemp[BUFSIZE];
        CHAR tempBuffer[BUFSIZE];
    	CHAR getwindowsBuffer[BUFSIZE];
    
         // Get the temp path.
        dwRetVal = GetTempPath(dwBufSize, tempBuffer); 
    	
    	
        if (dwRetVal > dwBufSize || (dwRetVal == 0))
        {
            printf ("GetTempPath failed (%d)\n", GetLastError());
        }
    
    	std::string tpath;
    	tpath = tempBuffer;
    	std::cout << tpath << " : Is the Temp Directory path\n";
    	
    	// Get Windows Directory.
    	dwRetVal = 0;
    	dwRetVal = GetWindowsDirectory(getwindowsBuffer, dwBufSize); 
    
    	    if (dwRetVal > dwBufSize || (dwRetVal == 0))
        {
            printf ("GetWindowsDirectory failed (%d)\n", GetLastError());
            
        }
    
    	std::string wpath;
    	wpath = getwindowsBuffer;
    	std::cout << wpath << " : Is the Windows Directory path\n";
    
    	dwRet = GetEnvironmentVariable(VARNAME, envtemp, BUFSIZE);
    
    	if(0 == dwRet)
        {
            dwErr = GetLastError();
            if( ERROR_ENVVAR_NOT_FOUND == dwErr )
            {
                printf("Environment variable does not exist.\n");
            }
    		else
    		{
    			printf("GetEnvironmentVariable failed ( function call not supported )(%d)\n", dwErr);
    			return FALSE;
    		}
        }
    	else if(BUFSIZE < dwRet)
        {
           
                printf("GetEnvironmentVariable failed (%d)\n", GetLastError());
                return FALSE;
        }
    
    	std::string envpath;
    	envpath = envtemp;
    	printf("%s : Is the path for variable %s\n", envtemp, VARNAME);	
    	return (0);   
    }
    Just last question:

    Under Windows2000 and above the program above returns the User Temp Directory, but under Windows 98 it returns the Windows Temp Directory!
    Could it be that Windows 98 does not have a User Temp Directory or i must use another API function to get it ?

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    95/98 uses Windows\Temp AFAIK.
    And another tip for you:
    http://cpwiki.sf.net/Indentation
    Indentation is import.
    But perhaps you might need to read
    http://cpwiki.sf.net/User:Elysia/Indentation
    too.

    Tell me if you find one better than the other and if anything is missing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Wow, are there still people actually using Windows 9x?

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Moving this to the Windows forum.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Quote Originally Posted by Elysia View Post
    Tell me if you find one better than the other and if anything is missing.
    Very nice, thank you

    Quote Originally Posted by cpjust
    Wow, are there still people actually using Windows 9x?
    I do not understand you ! Sure there are still people using Windows9x

Popular pages Recent additions subscribe to a feed