Article View: borland.public.cppbuilder.nativeapi
Article #12607Re: Searching for an deleting files
From: Remy Lebeau (TeamB)
Date: Sun, 30 Nov 2003 07:08
Date: Sun, 30 Nov 2003 07:08
54 lines
3026 bytes
3026 bytes
"Greg Stantin" <gstantin@stantonassoc.com> wrote in message
news:3fc98016@newsgroups.borland.com...
> it won't parse into sub-directories. I guess i am missing something
still.
It is the exact same code that you originally had, just with DeleteFile()
added but is otherwise the same logic as earlier. So if you are not able to
recurse into subfolders, that is a problem that your original code had all
along. And in fact, there is a problem with your original code - you are
specifically omitting directories from your Mask, so the test for
FILE_ATTRIBUTE_DIRECTORY will always fail because FindFirst/NextFile() will
never find any directories, only files. You must specify a Mask of "*.*" in
order for FindFirstFile() to include folders in the search, and then test
the file extensions manually. For example:
// notice the "*" is removed from the mask
DeleteFilesInDirectory("C:\\temp\\", ".old");
void TForm1::DeleteFilesInDirectory(const String &Directory, const
String &Mask)
{
WIN32_FIND_DATA Data;
HANDLE hFile = FindFirstFile((Directory + "*.*").c_str(), &Data);
if( hFile != INVALID_HANDLE_VALUE )
{
do
{
String sName(Data.cFileName);
if( (sName != ".") && (sName != "..") )
{
if( (Data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
!= 0 )
DeleteFilesInDirectory(Directory + sName + "\\",
Mask);
else
{
if( AnsiSameText(ExtractFileExt(sName), Mask) )
{
//DeleteFile(Directory + sName);
ListBox1->Items->Add(Directory + sName);
}
}
}
}
while( FindNextFile(hFile, &Data) );
FindClose(hFile);
}
}
Gambit
Technical Details
Message-ID:
<3fc99659@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fc97723@newsgroups.borland.com> <3fc97c1a@newsgroups.borland.com> <3fc98016@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,de74c80c594dbf57 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-29 23:10:36 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3fc97723@newsgroups.borland.com> <3fc97c1a@newsgroups.borland.com> <3fc98016@newsgroups.borland.com> Subject: Re: Searching for an deleting files Date: Sat, 29 Nov 2003 23:08:09 -0800 Lines: 56 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: 67.22.137.149 Message-ID: <3fc99659@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1070175833 67.22.137.149 (29 Nov 2003 23:03:53 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail