Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Phil V
Tue, 08 Apr 2003 09:51
Deleting multiple files?
Author: Phil V
Date: Tue, 08 Apr 2003 09:51
Date: Tue, 08 Apr 2003 09:51
17 lines
1472 bytes
1472 bytes
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
Re: Deleting multiple files?
Author: 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
>
>
Re: Deleting multiple files?
Author: Rodolfo Frino::Stargate Software
Date: Tue, 08 Apr 2003 10:43
Date: Tue, 08 Apr 2003 10:43
35 lines
1836 bytes
1836 bytes
Also, you might like to empty the recycle bin. If so, you can use
SHEmptyRecycleBin
with the flags SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND.
// Empty Recycle Bin
SHEmptyRecycleBin(Application->Handle, NULL,
SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI |
SHERB_NOSOUND);
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
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads