Re: remove non empty direcory
- From: "Stoyan Damov" <stoyan.maps.damov@xxxxxxxxx>
- Date: Wed, 4 May 2005 15:21:46 +0300
ShellExecute will execute any command you can pass to the Start/Run...
dialog. The file you're executing would be the command processor
(command.com on 9x and cmd.exe on NT-based OS). The parameters would be "/c
rd /s /q <folder>", /c for carrying the command and terminating the
processor, "rd /s /q full_path_to_folder_name" for unconditionally removing
the "folder_name" folder. If you have to create an empty folder after the
removal, just ShellExecute a "md full_path..." command. But the ShellExecute
"idea" was intended for fun only to answer your "simplest way" :) You
wouldn't want to use ShellExecute in production code (I hope).
You'd test whether a directory exists by calling CreateDirectory and
inspecting the return result, then if it exists, you'd recurse all
sub-directories with FindFirst/FindNext, calling DeleteFile for each file in
each sub-folder (or calling ShFileOperation to recursively delete them),
then delete each sub-folder by calling RemoveDirectory and you're done. I
guess you're looking for some ready code to paste (bad idea), but I don't
have one to provide you with, so take a look at the directory management
functions here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/directory_management_functions.asp
Cheers,
Stoyan
"François" <francois.aspert@xxxxxxx> wrote in message
news:4278b570$1@xxxxxxxxxxxxxxxxxxx
> Stoyan Damov wrote:
>> The simplest is this (for Windows): ShellExecute a "cmd /c rd /s /q
>> directory_name" :)
>> Next to it is recursing the folder's sub-folders, deleting all files,
>> then removing the sub-directories, finally removing the directory w/
>> FindFirst/Next (again for Windows).
>>
>> HTH,
>> Stoyan
>>
>> "François" <francois.aspert@xxxxxxx> wrote in message
>> news:42787916$1@xxxxxxxxxxxxxxxxxxx
>>
>>>Hello,
>>>
>>>I would like to know the simplest way ro remove a non empty directory
>>>using VC++ 6.0.
>>>
>>>thnks
>>>
>>>François
>>
>>
>>
>
> Thnks a lot but could you be more precise about the syntay that i should
> use because i've only seen this type of function:
>
> ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);
>
> Moreover, what i would like to do is:
>
> 1: test if a folder exists
> 2: if yes, remove it abd create a new one
> 3: if no, just create a new one
>
> Is it possible to do it with the shellexecute instruction again?
>
> bye
.
- References:
- remove non empty direcory
- From: François
- Re: remove non empty direcory
- From: Stoyan Damov
- Re: remove non empty direcory
- From: François
- remove non empty direcory
- Prev by Date: Re: how to permit only one instance of the program to run ?
- Next by Date: Re: how to permit only one instance of the program to run ?
- Previous by thread: Re: remove non empty direcory
- Next by thread: Re: remove non empty direcory
- Index(es):
Relevant Pages
|