Error message says unexpected |
for /r %x in (dir /b | findstr "TENDER_NUM 2") do copy "%x" dir_to_copy\
There are multiple errors in the above command.
You need to escape the
|
special character using^
:^|
You need to enclose
dir /b | findstr "TENDER_NUM 2"
with single quotes'
:'dir /b ^| findstr "TENDER_NUM 2"'
You need to use
for /f
instead offor /r
:for /f - Loop command against the results of another command.
for /r - Loop through files (Recurse subfolders).
Use the following command from a cmd
shell:
for /f %x in ('dir /b ^| findstr "TENDER_NUM 2"') do copy "%x" dir_to_copy\
In a batch file (replace %
with %%
):
for /f %%x in ('dir /b ^| findstr "TENDER_NUM 2"') do copy "%%x" dir_to_copy\
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- for /f - Loop command against the results of another command.
- for /r - Loop through files (Recurse subfolders).
- syntax - Escape Characters, Delimiters and Quotes.