简体   繁体   English

使用 Powershell 删除文件夹和内容

[英]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:这是我使用 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*. ", "C:\Users*\Documents*. ", "C:\Users*\Documents*. ",

rip and that was the folder i was working with.. RIP! rip,那是我正在使用的文件夹.. RIP! i changed it to我把它改成

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

now it works!!现在它起作用了! thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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