我需要帮助将以下Linux / Mac命令转换为Windows批处理脚本。
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文件(格式如上)并删除它们。
对不起,我是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/nullBasically 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.
Sorry, I'm new to Windows batch files.
最满意答案
你真的不解释你的象形文字是什么意思。
在批处理文件中
@echo off setlocal dir /s "c:\local root\Excel_*.xls"将显示所有匹配起始Excel_和扩展名.xls的文件
(如果这是你想要的,只需用del替换dir就会删除它们;添加>nul会抑制消息;添加2>nul抑制错误消息)
如果你想要文件以Excel_然后是任何alphas-only,那么
for /f "delims=" %%a in ('dir /b /s /a-d Excel_*.xls ^| findstr /E /R "\\Excel_[a-z]*\.xls" ') do echo "%%a"dir以/b (基本)形式(即.name-only) /s生成目录列表,其中包含子目录(附加完整目录名称)和/ad禁止目录名称。 这通过管道传输到过滤掉所需的文件名。 结果%%a逐行分配给%%a ,而delims=表示“不标记数据”
应该显示符合该标准的所有文件 - 但它会区分大小写; 添加/i到findstr开关,使其不区分大小写。 (/ r表示在findstr的限制实现中的“正则表达式”; / e表示“结束” - 我倾向于使用这些超过$ ) \\用于实现转义\以确保文件名匹配完成(即不找到“some_prefixExcel_whatever.xls” - 我会留下什么\.是为了你的想象力......
(再次,将echo更改为del以删除并在需要时添加重定向方法)
另一个正则表达式 - 好吧,跟随弹跳球。 看起来你想要.ppt文件的名称开始presentation然后是一系列数字,然后是一系列字母。 我建议
findstr /e /r "\\presentation[0-9]*[a-z]*\.ppt" for that task.You really don't explain what your hieroglypics mean.
In a batch file,
@echo off setlocal dir /s "c:\local root\Excel_*.xls"would show all of the files matching starting Excel_ with extension .xls
(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)
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"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"
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...
(again, change echo to del to delete and add in the redirection palaver if required)
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批处理脚本,用于搜索要删除的特定文件(Windows batch script to search for specific files to delete)我需要帮助将以下Linux / Mac命令转换为Windows批处理脚本。
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文件(格式如上)并删除它们。
对不起,我是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/nullBasically 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.
Sorry, I'm new to Windows batch files.
最满意答案
你真的不解释你的象形文字是什么意思。
在批处理文件中
@echo off setlocal dir /s "c:\local root\Excel_*.xls"将显示所有匹配起始Excel_和扩展名.xls的文件
(如果这是你想要的,只需用del替换dir就会删除它们;添加>nul会抑制消息;添加2>nul抑制错误消息)
如果你想要文件以Excel_然后是任何alphas-only,那么
for /f "delims=" %%a in ('dir /b /s /a-d Excel_*.xls ^| findstr /E /R "\\Excel_[a-z]*\.xls" ') do echo "%%a"dir以/b (基本)形式(即.name-only) /s生成目录列表,其中包含子目录(附加完整目录名称)和/ad禁止目录名称。 这通过管道传输到过滤掉所需的文件名。 结果%%a逐行分配给%%a ,而delims=表示“不标记数据”
应该显示符合该标准的所有文件 - 但它会区分大小写; 添加/i到findstr开关,使其不区分大小写。 (/ r表示在findstr的限制实现中的“正则表达式”; / e表示“结束” - 我倾向于使用这些超过$ ) \\用于实现转义\以确保文件名匹配完成(即不找到“some_prefixExcel_whatever.xls” - 我会留下什么\.是为了你的想象力......
(再次,将echo更改为del以删除并在需要时添加重定向方法)
另一个正则表达式 - 好吧,跟随弹跳球。 看起来你想要.ppt文件的名称开始presentation然后是一系列数字,然后是一系列字母。 我建议
findstr /e /r "\\presentation[0-9]*[a-z]*\.ppt" for that task.You really don't explain what your hieroglypics mean.
In a batch file,
@echo off setlocal dir /s "c:\local root\Excel_*.xls"would show all of the files matching starting Excel_ with extension .xls
(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)
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"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"
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...
(again, change echo to del to delete and add in the redirection palaver if required)
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.
发布评论