delete-directory

How to delete a folder with files using Java

风格不统一 提交于 2020-01-18 13:18:09
问题 I want to create and delete a directory using Java, but it isn't working. File index = new File("/home/Work/Indexer1"); if (!index.exists()) { index.mkdir(); } else { index.delete(); if (!index.exists()) { index.mkdir(); } } 回答1: Java isn't able to delete folders with data in it. You have to delete all files before deleting the folder. Use something like: String[]entries = index.list(); for(String s: entries){ File currentFile = new File(index.getPath(),s); currentFile.delete(); } Then you

How to delete a folder with files using Java

社会主义新天地 提交于 2020-01-18 13:16:38
问题 I want to create and delete a directory using Java, but it isn't working. File index = new File("/home/Work/Indexer1"); if (!index.exists()) { index.mkdir(); } else { index.delete(); if (!index.exists()) { index.mkdir(); } } 回答1: Java isn't able to delete folders with data in it. You have to delete all files before deleting the folder. Use something like: String[]entries = index.list(); for(String s: entries){ File currentFile = new File(index.getPath(),s); currentFile.delete(); } Then you

How to delete a folder in C++?

拜拜、爱过 提交于 2019-12-28 02:50:09
问题 How can I delete a folder using C++? If no cross-platform way exists, then how to do it for the most-popular OSes - Windows, Linux, Mac, iOS, Android? Would a POSIX solution work for all of them? 回答1: 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) 回答2: Delete folder (sub_folders and files) in Windows (VisualC++) not using Shell APIs, this is the best working sample

can't delete file from external storage in android programmatically

这一生的挚爱 提交于 2019-12-21 03:34:35
问题 I am trying to delete a file located at the path /storage/714D-160A/Xender/image/Screenshot_commando.png What I've done so far: try{ String d_path = "/storage/714D-160A/Xender/image/Screenshot_commando.png"; File file = new File(d_path); file.delete(); }catch(Exception e){ e.printStackTrace(); } and the file is still at its place(Not deleted :( ) Also I've given permission in Manifest file. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android

Can't delete a folder on Windows 7 with a trailing space [closed]

微笑、不失礼 提交于 2019-12-20 08:49:22
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Issue: I have a Windows 7 sub-directory which I can't delete. While I know others here, and many more elsewhere on the Internet have asked about this general class of Windows 7 file system problem, my question here specifically relates to the specific class of un-deletable files on Windows 7 which have a

Delete subfolders and files in vb.net

泄露秘密 提交于 2019-12-19 22:23:12
问题 Is it possible to delete all the subfolders (with content) and files within a folder? For example: Backup November pic1.jpg pic2.jpg December January pic3.jpg example1.txt example2.txt example3.txt There is a root folder (Backup). This root folder contains 3 subfolders (with content) and 3 text files. How can I delete the whole content (3 subfolders and 3 files) of the Backup folder without deleting the root folder (Backup) itself? 回答1: The Directory class has a Delete method that accepts a

Bash scripting: Deleting the oldest directory

偶尔善良 提交于 2019-12-18 06:07:10
问题 I want to look for the oldest directory (inside a directory), and delete it. I am using the following: rm -R $(ls -1t | tail -1) ls -1t | tail -1 does indeed gives me the oldest directory, the the problem is that it is not deleting the directory, and that it also list files. How could I please fix that? 回答1: This is not pretty but it works: rm -R $(ls -lt | grep '^d' | tail -1 | tr " " "\n" | tail -1) 回答2: rm -R "$(find . -maxdepth 1 -type d -printf '%T@\t%p\n' | sort -r | tail -n 1 | sed 's/

PHP: Simplest way to delete a folder (including its contents)

不羁的心 提交于 2019-12-17 18:06:06
问题 The rmdir() function fails if the folder contains any files. I can loop through all of the the files in the directory with something like this: foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') continue; unlink($dir.DIRECTORY_SEPARATOR.$item); } rmdir($dir); Is there any way to just delete it all at once? 回答1: Well, there's always system('/bin/rm -rf ' . escapeshellarg($dir)); where available. 回答2: rrmdir() -- recursively delete directories: function rrmdir($dir) { foreach

How to delete empty subfolders with PowerShell?

 ̄綄美尐妖づ 提交于 2019-12-17 17:44:28
问题 I have a share that is a "junk drawer" for end-users. They are able to create folders and subfolders as they see fit. I need to implement a script to delete files created more than 31 days old. I have that started with Powershell. I need to follow up the file deletion script by deleting subfolders that are now empty. Because of the nesting of subfolders, I need to avoid deleting a subfolder that is empty of files, but has a subfolder below it that contains a file. For example: FILE3a is 10

Deleting a directory results in application restart

寵の児 提交于 2019-12-17 16:39:39
问题 I have an application with 2 directories (books and export). If we create a book or a page of a book in the application a directory is added with the id of the page (this is for uploading resources). If we delete a page, the page (and it's directory) is removed from the database and the filesystem. However this resulted in a session loss (even an application restart). I've looked up some thing on google and found the following link. It seems to be a problem in ASP.NET 2.0 (and 3.5). Does