deleting files

hi,

I'm using NT 4.0, VC++ 5.0.

I want to write a function that deletes all the files "tmp*" from one of the libraries when I close my program.
(These were temporary files and I don't want them anymore)
How do I do it?
LVL 1
hilitAsked:
Who is Participating?
 
jstolanConnect With a Mentor Commented:
Pass in the wildcard search you wist to perform into the CFileFind class, then pass in the resulting file names into the DeleteFile function.  It will be sort of like this:

CFileFind finder;
BOOL bFound = finder.FindFile("c:\library\tmp*.*");
if( bFound )
{
    while( finder.FindNextFile() )
    {
        CString cszPath = finder.GetFilePAth();
        DeleteFile( cszPath );
    }
}
0
 
BridgeCommented:
Use CFileFind to cycle through the files and DeleteFile to remove them.
0
 
hilitAuthor Commented:
thanks,
one little thing - it should be "c:\\library\\tmp*.*" and not with 1 slash only.
0
 
cliffspielmanCommented:
How can this code be adjusted so that the deleted files are first copied to the Recycle Bin?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.