,当我想删除几个类似的目录(带通配符)时,我用这些命令删除它们:
示例文件夹:
public delegate void ShowFrm();
public partial class Camera : Form
{
public event ShowFrm eventForm;
private void Camera_FormClosing(object sender, FormClosingEventArgs e)
{
eventForm?.Invoke();
}
}
使用通配符删除文件夹的示例命令:
c:\Users\user\folder\
test1
test2
personalinfo
结果:
for /d %x in ("c:\Users\User\folder\test*") do rd /s /q "%x"
or
forfiles /P c:\Users\User\folder /M test* /C "cmd /c if @isdir==TRUE rmdir /s /q @file"
但不能使用%HOMEPATH%变量
c:\Users\User\folder\
personalinfo
但是%APPDATA%(或%HOMEDRIVE%\ Users \ User \ etc等)工作正常......非常罕见:
for /d %x in ("%HOMEPATH%\folder\test*") do rd /s /q "%x"
or
forfiles /P %HOMEPATH%\folder /M test* /C "cmd /c if @isdir==TRUE rmdir /s /q @file"
注意:在Win 7中测试。我不确定在Windows 8/10中是否发生了相同的事情
我该如何解决?提前致谢
答案 0 :(得分:1)
要为您的任务找到合适的环境变量,您可以在cmd窗口中发出(为其排除的路径长度):
> set |find /i "%USERNAME%"|find /i /V "Path"
APPDATA=C:\Users\UserName\AppData\Roaming
LOCALAPPDATA=C:\Users\UserName\AppData\Local
OneDrive=C:\Users\UserName\OneDrive
TEMP=C:\Users\UserName\AppData\Local\Temp
TMP=C:\Users\UserName\AppData\Local\Temp
USERNAME=UserName
USERPROFILE=C:\Users\UserName
但请注意,某些special folders
可能会重新定位到其他驱动器/文件夹。
您需要一个vb- / Jscript或PowerShell来评估这些位置。
在PowerShell提示符下:
PS> [environment]::getfolderpath("mydocuments")
C:\Users\LotPings\Documents
枚举特殊文件夹名称:
PS> [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])
并将所有特殊文件夹解析为其当前值:
[Environment+SpecialFolder]::GetNames(
[Environment+SpecialFolder])| Sort-Object | ForEach-Object{
"{0,22} {1}" -f $_,[Environment]::GetFolderPath($_)}
AdminTools C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools
ApplicationData C:\Users\LotPings\AppData\Roaming
CDBurning C:\Users\LotPings\AppData\Local\Microsoft\Windows\Burn\Burn
CommonAdminTools C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools
CommonApplicationData C:\ProgramData
CommonDesktopDirectory C:\Users\Public\Desktop
CommonDocuments C:\Users\Public\Documents
CommonMusic C:\Users\Public\Music
CommonOemLinks
CommonPictures C:\Users\Public\Pictures
CommonProgramFiles C:\Program Files\Common Files
CommonProgramFilesX86 C:\Program Files (x86)\Common Files
CommonPrograms C:\ProgramData\Microsoft\Windows\Start Menu\Programs
CommonStartMenu C:\ProgramData\Microsoft\Windows\Start Menu
CommonStartup C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
CommonTemplates C:\ProgramData\Microsoft\Windows\Templates
CommonVideos C:\Users\Public\Videos
Cookies C:\Users\LotPings\AppData\Local\Microsoft\Windows\INetCookies
Desktop C:\Users\LotPings\Desktop
DesktopDirectory C:\Users\LotPings\Desktop
Favorites C:\Users\LotPings\Favorites
Fonts C:\WINDOWS\Fonts
History C:\Users\LotPings\AppData\Local\Microsoft\Windows\History
InternetCache C:\Users\LotPings\AppData\Local\Microsoft\Windows\INetCache
LocalApplicationData C:\Users\LotPings\AppData\Local
LocalizedResources
MyComputer
MyDocuments C:\Users\LotPings\Documents
MyMusic C:\Users\LotPings\Music
MyPictures C:\Users\LotPings\Pictures
MyVideos C:\Users\LotPings\Videos
NetworkShortcuts C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Network Shortcuts
Personal C:\Users\LotPings\Documents
PrinterShortcuts C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
ProgramFiles C:\Program Files
ProgramFilesX86 C:\Program Files (x86)
Programs C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Recent C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Recent
Resources C:\WINDOWS\resources
SendTo C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\SendTo
StartMenu C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Start Menu
Startup C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
System C:\WINDOWS\system32
SystemX86 C:\WINDOWS\SysWOW64
Templates C:\Users\LotPings\AppData\Roaming\Microsoft\Windows\Templates
UserProfile C:\Users\LotPings
Windows C:\WINDOWS