?
Solved

DELETE TMP FILES

Posted on 2004-09-27
11
Medium Priority
?
405 Views
Last Modified: 2008-02-20
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
Comment
Question by:suma_ds
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 3

Expert Comment

by:domj
ID: 12166161
what language/environment?
0
 
LVL 6

Expert Comment

by:SCDMETA
ID: 12166392
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
 
LVL 1

Author Comment

by:suma_ds
ID: 12166549
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
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!

 
LVL 1

Expert Comment

by:shankar_ms
ID: 12172795
Use "SHFileOperation" ...
"GetTempPath" gives the temp path, using temp path and SHFileOperation you can cleanup the temp dir

SH
0
 

Expert Comment

by:int__main
ID: 12176493
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
 
LVL 1

Expert Comment

by:shankar_ms
ID: 12181981
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
 
LVL 1

Author Comment

by:suma_ds
ID: 12187111
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
 
LVL 4

Expert Comment

by:DaveyEss
ID: 12193991
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
 
LVL 1

Accepted Solution

by:
shankar_ms earned 200 total points
ID: 12195490
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
 
LVL 1

Author Comment

by:suma_ds
ID: 12197517
thanks :)
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Six Sigma Control Plans
Introduction to Processes

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question