简体   繁体   中英

'|' was unexpected this time

I was running the following command to echo pdf names starting with a number. But I get this error

| was unexpected this time

Code - FOR /f %a in ('dir /b|findstr "^[0-9][0-9]*.*\.pdf$"') DO echo %a

I think there is some problem with my cmd.

PS - I actually want to delete these files and will replace echo command with del afterwards

You can do your DIR first and pipe it into the command

dir /b | FOR /f %a in ('findstr "^[0-9][0-9]*.*\.pdf$"') DO echo %a

and if you want to be more efficient with your code given you know in this example you can prefilter the file extension,

dir /b *.pdf | FOR /f %a in ('findstr "^[0-9][0-9]*.*\.pdf$"') DO echo %a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM