Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

DELETE TMP FILES

heya

i would like to know,

what is the easiest and most efficient  i.e. best ;)   way to delete my tmp files after im done with them.

btw:
the tmp files r created using GetTempFileName()


Any help would be much appreciated,
suma
0
suma_ds
Asked:
suma_ds
  • 3
  • 3
  • 2
  • +3
1 Solution
 
domjCommented:
what language/environment?
0
 
SCDMETACommented:
Windows API CreateFile has a flag FILE_FLAG_DELETE_ON_CLOSE.  
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp
0
 
suma_dsAuthor Commented:
domj:
non-managed win32 c++, designed for windows XP/2000

SCDMETA:
unfortunately i am not using CreateFile.
i just use GetTempFileName to get a random file name, and then open it using the "fstream.h" class
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
shankar_msCommented:
Use "SHFileOperation" ...
"GetTempPath" gives the temp path, using temp path and SHFileOperation you can cleanup the temp dir

SH
0
 
int__mainCommented:
DaveyEss: i need a method that will work even if the file is open/in use by another process, and remove() dosnt do this. my bad, i really should have put more detailed specs in the question.



shankar_ms:

i dont think ima be using that method any time soon lol

compiling this code:

#include "shellapi.h"
#pragma comment (lib, "shell32.lib")

produces:

c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(55): error C2065: 'HDROP' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2065: 'HWND' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2065: 'LPPOINT' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2065: 'LPSTR' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2065: 'LPWSTR' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2078: too many initializers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2086: 'int DECLSPEC_IMPORT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2086: 'int DECLSPEC_IMPORT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2086: 'int DECLSPEC_IMPORT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2086: 'int DECLSPEC_IMPORT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2086: 'int DECLSPEC_IMPORT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2086: 'int DECLSPEC_IMPORT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2086: 'int DECLSPEC_IMPORT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2086: 'int EXTERN_C' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'EXTERN_C'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2086: 'int EXTERN_C' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'EXTERN_C'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2086: 'int EXTERN_C' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'EXTERN_C'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2086: 'int EXTERN_C' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'EXTERN_C'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2086: 'int EXTERN_C' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'EXTERN_C'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2086: 'int EXTERN_C' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'EXTERN_C'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2086: 'int EXTERN_C' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'EXTERN_C'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2086: 'int HINSTANCE' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68) : see declaration of 'HINSTANCE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2086: 'int STDAPICALLTYPE' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2086: 'int STDAPICALLTYPE' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2086: 'int STDAPICALLTYPE' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2086: 'int STDAPICALLTYPE' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2086: 'int STDAPICALLTYPE' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2086: 'int STDAPICALLTYPE' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2086: 'int UINT' : redefinition
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57) : see declaration of 'UINT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2144: syntax error : 'void' should be preceded by ';'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2146: syntax error : missing ')' before identifier 'hwnd'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2146: syntax error : missing ')' before identifier 'hwnd'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2146: syntax error : missing ';' before identifier 'BOOL'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2146: syntax error : missing ';' before identifier 'DragAcceptFiles'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2146: syntax error : missing ';' before identifier 'DragFinish'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2146: syntax error : missing ';' before identifier 'DragQueryFileA'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2146: syntax error : missing ';' before identifier 'DragQueryFileW'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2146: syntax error : missing ';' before identifier 'DragQueryPoint'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2146: syntax error : missing ';' before identifier 'HINSTANCE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2146: syntax error : missing ';' before identifier 'HINSTANCE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2146: syntax error : missing ';' before identifier 'HINSTANCE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2146: syntax error : missing ';' before identifier 'ShellExecuteA'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2146: syntax error : missing ';' before identifier 'ShellExecuteW'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2146: syntax error : missing ';' before identifier 'UINT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2146: syntax error : missing ';' before identifier 'UINT'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2182: 'STDAPICALLTYPE' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2182: 'STDAPICALLTYPE' : illegal use of type 'void'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2501: 'BOOL' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(55): error C2501: 'DECLARE_HANDLE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2501: 'DragAcceptFiles' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2501: 'DragFinish' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2501: 'DragQueryFileA' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2501: 'DragQueryFileW' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2501: 'DragQueryPoint' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(65): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(66): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2501: 'EXTERN_C' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2501: 'HINSTANCE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2501: 'HINSTANCE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): error C2501: 'HINSTANCE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2501: 'ShellExecuteA' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2501: 'ShellExecuteW' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2501: 'STDAPICALLTYPE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2501: 'STDAPICALLTYPE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(64): error C2501: 'STDAPICALLTYPE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(68): error C2501: 'STDAPICALLTYPE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(69): error C2501: 'STDAPICALLTYPE' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(57): error C2501: 'UINT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(58): error C2501: 'UINT' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\ShellAPI.h(75): fatal error C1003: error count exceeds 100; stopping compilation
0
 
shankar_msCommented:
Dont use "stdafx.h" in the header file. Use windows.h and and other releated headers and make the cpp file containing "shell API" calls to have the option "Not using pre compiled header".

SH
0
 
suma_dsAuthor Commented:
ahhh that's better... dam i think that's the first time ive ever got more than 100 errors X)

well anywayz i tested it out using this code:

      char TempPath[2048];
      GetTempPath(2048, TempPath);

      std::string d = TempPath;
      d += "*.*";

      SHFILEOPSTRUCT s;

      s.hwnd = NULL;
      s.wFunc = FO_DELETE;
      s.pFrom  = d.c_str();
      s.pTo = NULL;
      s.fFlags = FOF_SILENT;
      s.fAnyOperationsAborted = NULL;
      s.hNameMappings = NULL;
      s.lpszProgressTitle = NULL;

      SHFileOperation(& s);

but nuttin happened... can u give me any advice on how to make the above code work?

thankz,
suma
0
 
DaveyEssCommented:
I don't think you can delete a file that is in use.  The following link however gives some more examples  on how to delete files

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21036895.html
0
 
shankar_msCommented:
s.PFrom needs a double terminated string. Instead of
s.pFrom  = d.c_str();
do something like
TCHAR pFrom[MAX_PATH];
memset(pFrom,0,MAX_PATH);
_tcscpy(pFrom,d.c_str());
s.pFrom  = pFrom;

Aslo note that, do not use "d += "*.*"; because you might not have permission delete all the dir under temp.
Since you are using GetTempFileName(...) you will know the prefix of the files that you are creating. For example if my prefix is "tmp" then
use "d += "tmp*.*";

Based on your example here is the code

 TCHAR TempPath[MAX_PATH];
 memset(TempPath,0,MAX_PATH);
  GetTempPath(MAX_PATH, TempPath);
    std::string d = TempPath;
    d += "tmp*.*";
    TCHAR pFrom[MAX_PATH];
    memset(pFrom,0,MAX_PATH);
   _tcscpy(pFrom,d.c_str());
      
     SHFILEOPSTRUCT s;

     s.hwnd = NULL;
     s.wFunc = FO_DELETE;
     s.pFrom  = pFrom;
     s.pTo = NULL;
     s.fFlags =  FOF_NOCONFIRMATION  | FOF_SILENT;
     s.fAnyOperationsAborted = FALSE;
     s.hNameMappings = NULL;
     s.lpszProgressTitle = NULL;

     SHFileOperation(&s);



-Sh
0
 
suma_dsAuthor Commented:
thanks :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now