|
Answer» Hallo to everybody. I'm an italian user, so please forgive my poor english. I follow you from a lot of time but now I need your help so I've REGISTERED myself.
Now I explain my problem. I have to loop recursively a folder in order to find all the files that starts with 6 digits followed by some text, let's say A.csv.
I wrote this
dir /b /s | findstr /i ^[0-9][0-9][0-9][0-9][0-9][0-9]A.csv$
and it works but this command returns me the full paths. I'd like to have only filename. I know about the for command and ~n but I don't know if I can use it with findstr. Thanks in advance. for /f can parse the output of a command line. Use single quotes.
CODE: [Select]for /f "delims==" %%F in ('dir /b /s ^| findstr /i ^[0-9][0-9][0-9][0-9][0-9][0-9]A.csv$') do ( echo %%F )
Code: [Select]S:\Test\Batch\After 07-09-09\forfind\123452A.csv S:\Test\Batch\After 07-09-09\forfind\123453A.csv S:\Test\Batch\After 07-09-09\forfind\123454A.csv S:\Test\Batch\After 07-09-09\forfind\123455A.csv S:\Test\Batch\After 07-09-09\forfind\123456A.csv S:\Test\Batch\After 07-09-09\forfind\123451A.csv
~nxVariable is name + extension. See for /? for full list of variable modifiers.
remember to ESCAPE the pipe symbol | like this ^| or you will get an error
Code: [Select]for /f "delims==" %%F in ('dir /b /s ^| findstr /i ^[0-9][0-9][0-9][0-9][0-9][0-9]A.csv$') do ( echo %%~nxF )
Code: [Select]123452A.csv 123453A.csv 123454A.csv 123455A.csv 123456A.csv 123451A.csv Thank you very much Salmon. I didn't know about the escape char, indeed without it I received an error and this was the reason why I thought I couldn't use findstr within for. I've learned a NEW thing. Thanks again for your kindness and for the speed of your reply. Have a nice day. va bene
|