且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

基于正则表达式FINDSTR批处理脚本删除文件

更新时间:2023-12-05 19:52:22

  FOR / F令牌= *%%一个在('DIR / B ^ | FINDSTR MY_REGEX_HERE')DO ECHO %%一

逃离 | 使用 ^前

I'm trying to delete some files with a batch script, based on a regular expression. What I have is:

FOR /f "tokens=*" %%a in ('dir /b | findstr MY_REGEX_HERE') DO ECHO %%a 

I know my inner command works on its own, giving me the list of directories, but when I embed it in the for loop like this I get an error | was unexpected at this time. Is piping not allowed within FOR loop commands? Or do I need to escape it or something?

Any help on how I can do this would be great.

FOR /f "tokens=*" %%a in ('dir /b ^| findstr MY_REGEX_HERE') DO ECHO %%a 

Escape the | using a ^ before it.