Re: remove non empty direcory

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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


.



Relevant Pages

  • Re: ShellExecute
    ... The redirection operators, are part of the command ... Althought this API function is called "shellexecute" I doubt ... it's sending the command to the CLI; rather, ...
    (borland.public.delphi.nativeapi)
  • Re: executing MS-DOS command without flicker
    ... SW_HIDE) will make the window not show at all. ... > MS DOS command window appears if I use RUN/! ... I used> ShellExecute() method of _shellexecute ffc class but this also shows the> flicker. ... Is there a was to execute command in backgroud in VFP 8 (like SQL ...
    (microsoft.public.fox.programmer.exchange)
  • Re: send email with shellexecute but crlf in body does not work
    ... like opening up a DOS window and typing a command. ... > I try to send an email with shellexecute in FVP8 on Win2k with Outlook ... > Unfortunately the body text will not show my crlf. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: run something on command line
    ... Could you just call ShellExecute() to execute the command? ... Im creating a console application, but all i want it to do is to run ...
    (microsoft.public.vc.mfc)
  • Re: autorun.inf
    ... shellexecute e.. ... Remarks ... The open command specifies the path and file name of the application that AutoRun launches when a user inserts a disc in the drive. ... verb The verb that corresponds to the command. ...
    (microsoft.public.windowsxp.general)