简体   繁体   中英

delete folder and contents with Powershell

I'm trying to delete the contents of the users folder. It works for files but it leaves folders. How can I take folders with it? This is what i have tried using powershell:

$folders = @(
"C:\Users\*\Downloads\*",
"C:\Users\*\Downloads\*.*", 
"C:\Users\*\Documents\*.*", 
"C:\Users\*\Documents\*.*", 
"C:\Users\*\Pictures\*",
"C:\Users\*\Pictures\*.*",
"C:\Users\*\Desktop\*",
"C:\Users\*\Desktop\*.*",
"C:\Users\*\Videos\*",
"C:\Users\*\Videos\*.*")
foreach ($folder in $folders) {Remove-Item $folder -force -recurse -ErrorAction SilentlyContinue}
exit 0

How can i take parents folders in those folders and their child elemetns? I want complete empty Document, desktop etc.

I got it, im slightly stupid in my script i noted:

"C:\Users*\Documents*. ", "C:\Users*\Documents*. ",

rip and that was the folder i was working with.. RIP! i changed it to

"C:\Users*\Documents*", "C:\Users*\Documents*.*",

now it works!! thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM