Article View: borland.public.cppbuilder.nativeapi
Article #17166Re: Deleting multiple files?
From: Rodolfo Frino::Stargate Software
Date: Tue, 08 Apr 2003 10:25
Date: Tue, 08 Apr 2003 10:25
66 lines
2767 bytes
2767 bytes
One nice method is through the SHFileOperation API, which
I have put into a function
void Delete_AllFiles(TForm* pForm, char* s)
{
char Buffer[MAX_PATH];
// Create an object of the class SHFILEOPSTRUCT.
SHFILEOPSTRUCT oFile;
memset(Buffer, 0, sizeof(Buffer)); //Init Buffer to 0
memset(&oFile, 0, sizeof(oFile)); //Set Structure to 0
// Make the application (Form1) to be the Owner of the
// Progress Dialog Box that is displayed while
// the delete operation takes place
oFile.hwnd = pForm->Handle;
//Set the Operation to be performed
oFile.wFunc = FO_DELETE;
//Set the directory you want to delete
strcpy(Buffer, s);
oFile.pFrom = Buffer;
oFile.fFlags = FOF_ALLOWUNDO | FOF_SILENT | FOF_NOCONFIRMATION;
SHFileOperation(&oFile);
}
//----------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// Usage Examples
//Delete all files in the specified directory
Delete_AllFiles(Form1, "c:\\__TEST\\*.*");
// Delete an specific file or directory
Delete_AllFiles(Form1, Edit1->Text.c_str());
}
Rodolfo
"Phil V" <pvalentine_REMOVE_THIS_@_REMOVE_THIS_continental-microwave.co.uk>
wrote in message news:3e929bc3$1@newsgroups.borland.com...
> How do I delete either multiple files or even a whole directory, (whether
it
> be empty or not) ?
>
> I don't really want the user to be aware of the deletion as it is deleting
> file that are used by my application and are created without the user's
> interaction.
>
> Any ideas? If possible it should work on windows 9x and XP.
>
> Many thanks,
>
> Phil
>
>
> --
>
> "If it is called software, why is it so hard?" - Unknown
>
>
Technical Details
Message-ID:
<3e92a2eb@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3e929bc3$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,fd07c1abe21c07f X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-08 03:43:22 PST From: "Rodolfo Frino::Stargate Software" <rodolfofrino@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e929bc3$1@newsgroups.borland.com> Subject: Re: Deleting multiple files? Date: Tue, 8 Apr 2003 20:25:16 +1000 Lines: 68 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 NNTP-Posting-Host: 211.28.77.205 Message-ID: <3e92a2eb@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1049797355 211.28.77.205 (8 Apr 2003 03:22:35 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail