I need a batch script that will search in one folder or root, Not recursively, for folders with a folder name that has only two letters or numbers. Example A1 B0 E2 22 52 . I had a program that would dump folders on the C drive and i now i have hundreds of folders on many computers. I want to delete these folders. I do not have any folders as short as 2 letters that are needed. Can someone help?
我需要一个批处理脚本,它将在一个文件夹或根目录中搜索,而不是递归地搜索文件夹名称只有两个字母或数字的文件夹。实施例A1 B0 E2 22 52。我有一个程序,可以在C盘上转储文件夹,我现在在许多计算机上有数百个文件夹。我想删除这些文件夹。我没有任何文件夹,只需要2个字母。有人可以帮忙吗?
2 个解决方案
#1
0
this will delete all empty folders with two characters or less:
这将删除所有包含两个或更少字符的空文件夹:
for /f %%i in ('dir /b /ad ??') do rd %%i
for / f %% i in('dir / b / ad ??')do rd %% i
If you want also not-empty folders to be deleted:
如果您还想要删除非空文件夹:
for /f %%i in ('dir /b /ad ??') do rd %%i /s /q
If you use it not within a batchfile but as a single command, replace every %%i
with %i
如果您不是在批处理文件中使用它而是作为单个命令使用它,请将每个%% i替换为%i
EDIT (exclude a folder):
编辑(排除文件夹):
for /f %%i in ('dir /b /ad ??') do ( if "%%i" neq "FP" rd %%i /s /q )
#2
3
this removes only folders with two letters or digits in its name:
这将仅删除名称中包含两个字母或数字的文件夹:
for %%i in ('dir /b /ad ?? ^| findstr /r "^[a-z0-9][a-z0-9]$"') do echo rd /s /q "%%~i"
Look at the output and remove the word echo
if it looks good. For a more advenced use of Regex have a look at sed.
查看输出并删除单词echo,如果它看起来不错。对于更高级别使用正则表达式看看sed。
#1
0
this will delete all empty folders with two characters or less:
这将删除所有包含两个或更少字符的空文件夹:
for /f %%i in ('dir /b /ad ??') do rd %%i
for / f %% i in('dir / b / ad ??')do rd %% i
If you want also not-empty folders to be deleted:
如果您还想要删除非空文件夹:
for /f %%i in ('dir /b /ad ??') do rd %%i /s /q
If you use it not within a batchfile but as a single command, replace every %%i
with %i
如果您不是在批处理文件中使用它而是作为单个命令使用它,请将每个%% i替换为%i
EDIT (exclude a folder):
编辑(排除文件夹):
for /f %%i in ('dir /b /ad ??') do ( if "%%i" neq "FP" rd %%i /s /q )
#2
3
this removes only folders with two letters or digits in its name:
这将仅删除名称中包含两个字母或数字的文件夹:
for %%i in ('dir /b /ad ?? ^| findstr /r "^[a-z0-9][a-z0-9]$"') do echo rd /s /q "%%~i"
Look at the output and remove the word echo
if it looks good. For a more advenced use of Regex have a look at sed.
查看输出并删除单词echo,如果它看起来不错。对于更高级别使用正则表达式看看sed。