Answer the question
In order to leave comments, you need to log in
How to delete all files and subfolders within a folder, preferably using PowerShell?
Good afternoon community.
There is a structure, something like this.
files
-01. Folder name
--One folder
--Two folder to be deleted
---folder
---mother
---files
-02. Folder name
--One folder
--Two folder to be deleted
---folder
---mother
---files
How to write a script that would delete everything inside folders "Two folder to be deleted" - files, folders, hidden files, absolutely everything.
I managed to write this:
$path = "d:\files\01. Имя папки\Два папка, которую надо удалить\"
$path2 = "d:\files\02. Имя папки\Два папка, которую надо удалить\"
if (Test-Path $path)
{
$path + " Exists"
Remove-Item -path $path -Recurse -Force
[System.Threading.Thread]::Sleep(1500)
}
else
{
Write-host -foregroundcolor Red $path " Does not exist"
}
if (Test-Path $path2) {
$path2 + " Exists"
Remove-Item -path $path2 -Recurse -Force
[System.Threading.Thread]::Sleep(1500)
}
else
{
Write-host -foregroundcolor Red $path2 " Does not exist"
}
Answer the question
In order to leave comments, you need to log in
if the previous answer did not help, do those folders that need to be deleted have any distinguishing feature? you need something that you can catch on with the logic of the script.
for example, if you make a dir, the desired folder will always be the second (first, eighth, etc.) in the list if sorted by name, for example, or not?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question