delete-directory

Delete folder and all files/subdirectories

守給你的承諾、 提交于 2019-11-27 03:14:37
问题 How can I delete a folder with all it's files/subdirectories (recursive deletion) in C++? 回答1: Seriously: system( "rm -rf /path/to/directory" ) Perhaps more what you're looking for, but unix specific: /* Implement system( "rm -rf" ) */ #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <sys/syslimits.h> #include <ftw.h> /* Call unlink or rmdir on the path, as appropriate. */ int rm( const char *path, const struct stat *s, int flag, struct FTW *f ) { int status; int (*rm_func)

How do I delete a directory with read-only files in C#?

家住魔仙堡 提交于 2019-11-26 17:25:50
I need to delete a directory that contains read-only files. Which approach is better: Using DirectoryInfo.Delete() , or, ManagementObject.InvokeMethod("Delete") ? With DirectoryInfo.Delete() , I have to manually turn off the read-only attribute for each file, but ManagementObject.InvokeMethod("Delete") doesn't appear to need to. Is there any situation where one is more preferable to the other? Sample code (test.txt is read only). First way: DirectoryInfo dir = new DirectoryInfo(@"C:\Users\David\Desktop\"); dir.CreateSubdirectory("Test"); DirectoryInfo test = new DirectoryInfo(@"C:\Users\David

How to delete a whole folder and content?

≡放荡痞女 提交于 2019-11-26 15:38:53
I want the users of my application to be able to delete the DCIM folder (which is located on the SD card and contains subfolders). Is this possible, if so how? chikka.anddev Let me tell you first thing you cannot delete the DCIM folder because it is a system folder. As you delete it manually on phone it will delete the contents of that folder, but not the DCIM folder. You can delete its contents by using the method below: Updated as per comments File dir = new File(Environment.getExternalStorageDirectory()+"Dir_name_here"); if (dir.isDirectory()) { String[] children = dir.list(); for (int i =

How do I delete a directory with read-only files in C#?

放肆的年华 提交于 2019-11-26 06:06:27
问题 I need to delete a directory that contains read-only files. Which approach is better: Using DirectoryInfo.Delete() , or, ManagementObject.InvokeMethod(\"Delete\") ? With DirectoryInfo.Delete() , I have to manually turn off the read-only attribute for each file, but ManagementObject.InvokeMethod(\"Delete\") doesn\'t appear to need to. Is there any situation where one is more preferable to the other? Sample code (test.txt is read only). First way: DirectoryInfo dir = new DirectoryInfo(@\"C:\

How to delete a whole folder and content?

核能气质少年 提交于 2019-11-26 05:55:41
问题 I want the users of my application to be able to delete the DCIM folder (which is located on the SD card and contains subfolders). Is this possible, if so how? 回答1: Let me tell you first thing you cannot delete the DCIM folder because it is a system folder. As you delete it manually on phone it will delete the contents of that folder, but not the DCIM folder. You can delete its contents by using the method below: Updated as per comments File dir = new File(Environment

How do I recursively delete a directory and its entire contents (files + sub dirs) in PHP?

≡放荡痞女 提交于 2019-11-26 03:16:19
问题 How do I delete a directory and its entire contents (files and subdirectories) in PHP? 回答1: 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."/".$object) && !is_link($dir."/".$object)) rrmdir($dir."/".$object); else unlink($dir."/".$object); } } rmdir($dir); } } 回答2: Building on The Pixel