How to delete a folder in C++?
I strongly advise to use Boost.FileSystem. http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/index.htm In your case that would be boost::filesystem::remove_all(yourPath)
I strongly advise to use Boost.FileSystem. http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/index.htm In your case that would be boost::filesystem::remove_all(yourPath)
Just a one-liner. import org.apache.commons.io.FileUtils; FileUtils.deleteDirectory(new File(destination)); Documentation here
Simplest way of avoiding recursive calls is by utilising the AllDirectories option when getting FileSystemInfos, like so: public static void ForceDeleteDirectory(string path) { var directory = new DirectoryInfo(path) { Attributes = FileAttributes.Normal }; foreach (var info in directory.GetFileSystemInfos(“*”, SearchOption.AllDirectories)) { info.Attributes = FileAttributes.Normal; } directory.Delete(true); }
You can delete files and folders recursively like this: void deleteRecursive(File fileOrDirectory) { if (fileOrDirectory.isDirectory()) for (File child : fileOrDirectory.listFiles()) deleteRecursive(child); fileOrDirectory.delete(); }
You should check out Apache’s commons-io. It has a FileUtils class that will do what you want. FileUtils.deleteDirectory(new File(“directory”));
The user-contributed section in the manual page of rmdir contains a decent implementation: function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != “.” && $object != “..”) { if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir.”https://stackoverflow.com/”.$object)) rrmdir($dir. DIRECTORY_SEPARATOR .$object); else unlink($dir. DIRECTORY_SEPARATOR .$object); } } rmdir($dir); } }