🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10621

Windows temp dir problem

#10621
From: Martin C
Date: Wed, 31 Mar 2004 19:08
75 lines
3357 bytes
Hi all,

I am trying to locate my windows temp directory and erase all its contents,
so I am using the following code to 1) locate the windows temp directory. 2)
erase all the directory contents.
The problem I am facing is that the temp directory contents never get
erased, although when I try to delete them manually they get deleted
normally! So can someone please tell me where is my mistake exactly


Thank you for your help and cooperation


void __fastcall TForm1::Button1Click(TObject *Sender)
{
   CHAR szPath[MAX_PATH];
   if(GetTempPath(MAX_PATH, szPath))
   {  EraseAllFolderContents(szPath, "*.*");
   }
}
//--------------------------------------------------------------------------
-
bool __fastcall TForm1::EraseAllFolderContents(const AnsiString &Folder,
const AnsiString &MaskToFind)
{ //erase all contents of the folder

        WIN32_FIND_DATA wfd;
        HANDLE hFind;
        String sFullPath, sFindFilter, sCurrentFolder;
        bool Result = true;

        sCurrentFolder = IncludeTrailingBackslash(Folder);
        sFindFilter = sCurrentFolder + "*.*";

        hFind = FindFirstFile(sFindFilter.c_str(), &wfd);
        if( hFind != INVALID_HANDLE_VALUE )
        {
            do
            {
                if( (_tcscmp(wfd.cFileName, _T(".")) == 0) ||
(_tcscmp(wfd.cFileName, _T("..")) == 0) )
                    continue;

                sFullPath = sCurrentFolder + String(wfd.cFileName);

                if(wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
                {
                    Result = SetFileAttributes(sFullPath.c_str(),
wfd.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
                    if(!Result)
                        break;
                }

                if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                {
                    Result = EraseAllFolderContents(sFullPath, MaskToFind);
                    if(Result)
                        Result = RemoveDirectory(sFullPath.c_str());
                }
                else
                {
                    if(MatchesMask(wfd.cFileName, MaskToFind))
                    {
                        Result = DeleteFile(sFullPath);
                    }
                }
            }
            while((Result) && (FindNextFile(hFind, &wfd)));
            FindClose(hFind);
        }

  return Result;
}
//--------------------------------------------------------------------------
--
Technical Details
Message-ID: <406b7a09$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,c9cba57ee1c8629d,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-03-31 18:40:13 PST
From: "Martin C" <martincplus@hotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Windows temp dir problem
Date: Wed, 31 Mar 2004 21:08:37 +0200
Lines: 77
Organization: V Safe
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 81.10.4.238
Message-ID: <406b7a09$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1080785417 81.10.4.238 (31 Mar 2004 18:10:17 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail