Batch Script Doesnt删除文件夹中的文件夹.txt文件:(



我的批处理文件的代码是:

for /f "delims=" %%f in (7profiledeletelist.txt) do rd /s /q "%%f"
PAUSE
exit

在"7profiledeletelist.txt"中,有:(将被删除)

C:Users1* (I tried *.* it didnt work)
C:Users2* (I tried *.* it didnt work)
C:Users3* (I tried *.* it didnt work)
C:Users4* (I tried *.* it didnt work)
C:Users5* (I tried *.* it didnt work)
C:Users6* (I tried *.* it didnt work)
C:Users7* (I tried *.* it didnt work)
C:Users8* (I tried *.* it didnt work)
C:Users9* (I tried *.* it didnt work)
C:UsersM* (I tried *.* it didnt work)
C:UsersT* (I tried *.* it didnt work)

但是通过这个7profiledeletelist.txt,bat文件不能删除任何内容。如果我去掉*并写下确切的名字,效果会很好。我想删除用户中以M-T和1到9开头的所有文件夹。如何更改"7profiledeletelist.txt"或批处理脚本。批处理脚本中是否存在错误代码?提前感谢:(

我们可以将排除文件夹(例如:文件夹325和文件夹265)添加到该批中,而不是删除吗?

rd将不接受通配符,因此,需要在对文件夹的完整引用中转换通配符。使用额外的for

for /f "delims=" %%f in (7profiledeletelist.txt) do (
    for /d %%a in ("%%f") do rd /s /q "%%~fa"
)

编辑以适应评论。如何在过程中排除文件夹

(
    cmd /q /c "(for /f "delims=" %%f in (7profiledeletelist.txt) do for /d %%a in ("%%f") do echo(%%~fa)" 
) | ( 
    for /f "delims=" %%a in ('findstr /l /v /g:exclude.txt') do @rd /s /q "%%a"
)

第一个命令将生成所有文件夹的列表,第二个命令将过滤该列表,过滤掉exclude.txt文件中指示的文件夹。此文件需要为每个排除的文件包含一行。实际需求将决定行的格式或findstr命令的参数。

相关内容

最新更新