Tag for questions regarding directory (folder) deletion. O.S. independent.
Questions tagged [delete-directory]
104 questions
447
votes
21 answers
How to recursively delete an entire directory with PowerShell 2.0?
What is the simplest way to forcefully delete a directory and all its subdirectories in PowerShell? I am using PowerShell V2 in Windows 7.
I have learned from several sources that the most obvious command, Remove-Item $targetDir -Recurse -Force,…

Matt Spradley
- 7,854
- 9
- 31
- 40
436
votes
26 answers
Delete directories recursively in Java
Is there a way to delete entire directories recursively in Java?
In the normal case it is possible to delete an empty directory.
However when it comes to deleting entire directories with contents, it is not that simple anymore.
How do you delete…

paweloque
- 18,466
- 26
- 80
- 136
226
votes
25 answers
How to delete a whole folder and content?
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?

Beginner
- 28,539
- 63
- 155
- 235
220
votes
22 answers
Ansible: How to delete files and folders inside a directory?
The below code only deletes the first file it gets inside the web dir. I want to remove all the files and folders inside the web directory and retain the web directory. How can I do that?
- name: remove web dir contents
file:…

Abbas
- 3,144
- 2
- 25
- 45
186
votes
21 answers
How to fix "containing working copy admin area is missing" in SVN?
I deleted manually a directory I just added, offline, in my repository. I can't restore the directory.
Any attempt to do an update or a commit will fail with:
"blabla/.svn" containing working copy admin area is missing.
I understand why, but is…

Bite code
- 578,959
- 113
- 301
- 329
162
votes
21 answers
How do I recursively delete a directory and its entire contents (files + sub dirs) in PHP?
How do I delete a directory and its entire contents (files and subdirectories) in PHP?

Itay Moav -Malimovka
- 52,579
- 61
- 190
- 278
158
votes
30 answers
How to delete a folder with files using Java
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();
}
}

Mr.G
- 3,413
- 2
- 16
- 20
141
votes
7 answers
SVN undo delete before commit
If you delete a directory from an SVN working copy, but haven't committed yet, it's not obvious how to get it back. Google even suggests "svn undo delete before commit" as a common query when you type "svn undo d", but the search results are…

LaC
- 12,624
- 5
- 39
- 38
112
votes
10 answers
In Unix, how do you remove everything in the current directory and below it?
I know this will delete everything in a subdirectory and below it:
rm -rf
But how do you delete everything in the current directory as well as every subdirectory below it and the contents of all of those subdirectories?

Yen
- 2,176
- 3
- 19
- 27
99
votes
8 answers
How to delete directory content in Java?
After enumerating a directory, I now need to delete all the files.
I used:
final File[] files = outputFolder.listFiles();
files.delete();
But this hasn't deleted the directory.

lola
- 5,649
- 11
- 49
- 61
62
votes
11 answers
How do I delete a directory with read-only files in C#?
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…

David Hodgson
- 10,104
- 17
- 56
- 77
59
votes
18 answers
How to delete a folder in C++?
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?

user88240
- 609
- 1
- 5
- 4
33
votes
7 answers
PHP: Simplest way to delete a folder (including its contents)
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;
…

Chris B
- 15,524
- 5
- 33
- 40
30
votes
7 answers
How to delete empty subfolders with PowerShell?
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…

ScriptSearcher
- 303
- 1
- 3
- 4
26
votes
5 answers
Can't delete a folder on Windows 7 with a trailing space
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…

Elliptical view
- 3,338
- 1
- 31
- 28