Windows批处理脚本以搜索要删除的特定文件 [英] Windows batch script to search for specific files to delete
问题描述
我需要帮助将以下Linux/Mac命令转换为Windows批处理脚本.
I need help converting the following Linux/Mac commands into a Windows batch script.
find / -regex ``^.*/Excel_[a-z]*.xls'' -delete 2>/dev/null
find / -regex ``^.*/presentation[0-9]*[a-z]*.ppt'' -delete 2>/dev/null
基本上使用正则表达式,我需要在给定的Windows框中找到任何.xls/.ppt文件(采用上述格式)并将其删除.
Basically using regular expressions, I need to find any of the .xls/.ppt files (in the format above) in a given Windows box and delete them.
对不起,我是Windows批处理文件的新手.
Sorry, I'm new to Windows batch files.
推荐答案
您真的不解释您的象形文字是什么意思.
You really don't explain what your hieroglypics mean.
在批处理文件中,
@echo off
setlocal
dir /s "c:\local root\Excel_*.xls"
将显示所有以Excel_
开头且扩展名为.xls
would show all of the files matching starting Excel_
with extension .xls
(如果您要这样做,只需将dir
替换为del
即可删除它们;添加>nul
可以禁止显示消息;添加2>nul
可以禁止显示错误消息)
(and if that's what you want, simply replacing dir
with del
would delete them; adding >nul
would suppress messages; adding 2>nul
suppresses error messages)
如果您希望文件以Excel_
开头,然后是任何纯字母开头,则
If you want files starting Excel_
then followed by any alphas-only, then
for /f "delims=" %%a in ('dir /b /s /a-d Excel_*.xls ^| findstr /E /R "\\Excel_[a-z]*\.xls" ') do echo "%%a"
dir
产生/b
(基本)格式(即仅文件名)的目录列表/s
-带有子目录(附加完整目录名称),而/a-d
禁止显示目录名称.它通过管道传送到findstr
以过滤出所需的文件名.结果逐行分配给%%a
,并且delims=
表示不要标记数据"
The dir
produces a directory list in /b
(basic) form (ie. filename-only) /s
- with subdirectories (which attaches the full directory name) and the /a-d
suppresses directorynames. This is piped to findstr
to filter out the required filenames. The result is assigned to %%a
line-by-line, and the delims=
means "don't tokenise the data"
应向您显示所有符合该条件的文件-但大小写敏感;将/i
添加到findstr
开关以使其不区分大小写. (/r表示findstr
受限制的实现中的"regex";/e表示结束"-我倾向于在$
上使用它们).\\
旨在实现转义的\
以确保文件名匹配完成后(即找不到"some_prefixExcel_whatever.xls")-我将把\.
打算做的事情留给您发挥想象力...
should show you all the files matching that criterion - but it would be case-sensitive; add /i
to the findstr
switches to make it case-insensitive. (/r means "regex" within findstr
's restricted implementation; /e means "ends" - I tend to use these over $
) The \\
in intended to implement escaped \
to ensure the filename match is complete (ie do't find "some_prefixExcel_whatever.xls) - I'll leave what \.
is intended to do to your imagination...
(同样,将echo
更改为del
以删除并在需要时添加重定向程序)
(again, change echo
to del
to delete and add in the redirection palaver if required)
另一个正则表达式-好吧,跟随弹跳球.似乎您想要的文件名称以presentation
开头的.ppt
文件,然后是一系列可能的数字,然后是一系列的字母.我建议
And the other regex - well, follow the bouncing ball. It would appear you want .ppt
files with names starting presentation
followed by a possible series of numerics then by a series of alphabetics. I'd suggest
findstr /e /r "\\presentation[0-9]*[a-z]*\.ppt" for that task.
这篇关于Windows批处理脚本以搜索要删除的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!