CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Location
    California, USA
    Posts
    34

    how to delete directory and its content?



    How can I delete the whole directory regardless whether it is empty or not? I've tried RemoveDirectory(), remove() function, but their all failed when there is file or subdirectory in the directory.

  2. #2
    Join Date
    Apr 1999
    Posts
    3

    Re: how to delete directory and its content?



    No Win32 API function can delete the whole directory ! You must implement this

    by RemoveDirectory() and DeleteFile().

  3. #3
    Join Date
    May 1999
    Posts
    123

    Re: how to delete directory and its content?



    You can do a recursive search, finding and deleting all the contents of the directory before you attempt to delete the directory itself.


    Alternatively, you can use SHFileOperation to delete the entire directory at once.



  4. #4
    Join Date
    Mar 2001
    Location
    Gauteng, South Africa
    Posts
    3

    Re: how to delete directory and its content?

    The easiest way I found was to get my program to create a bat file on the fly that contains the following:
    @Echo Off
    rd [dir_to_be_deleted] /S /Q

    I then call this bat file from my C++ program using CreateProcess(). Once the bat file has finished, I remove it (the bat file) from the location I created it on using remove(path_and_file). Therefore the directory and bat file are removed from the user's hard drive.

    I've tried the recursive route, but trust me, this is much simpler!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured