0

when I run the following command in cmd manually, it works

for /F "delims=" %f in ('dir /B C:\Users\DMS\Downloads\*^|FileByAge.exe 2') do echo %f

However, when I put that command in a batch file and run it, I get the following:

\Users\DMS\Downloads\*|FileByAge.exe was unexpected at this time.
for /F "delims=" \Users\DMS\Downloads\*^|FileByAge.exe 2') do echo f

Any suggestion?

I am tying to make the answer from (Find out if file is older than 4 hours in Batch file) work in my case

Community
  • 1
  • 1
help
  • 809
  • 5
  • 18
  • 35
  • 2
    Use `%%f` instead of `%f` in a batch file; type `for /?` in a command prompt window for details... – aschipfl Jan 20 '16 at 23:32

1 Answers1

2

You need to use %% instead of % for for loop variables inside batch files.

for /F "delims=" %%f in ('dir /B C:\Users\DMS\Downloads\*^|FileByAge.exe 2') do echo %%f
SomethingDark
  • 13,229
  • 5
  • 50
  • 55