I have a one liner batch command that sorts files by date and then deletes everything but the last 10. This command runs just fine when I run it in a CMD window. However, when I place it in a BAT file, I get errors.
Command (works OK in CMD window):
for /f "skip=10 delims=" %A in ('dir /a:-d /b /o:-d /t:c *.jpg ^2^>nul') do del %A
Errors I get if trying to run it in a batch file:
Q:\Testbk>test1
-d was unexpected at this time.
Q:\Testbk>for /f "skip=10 delims=" -d /b /o:-d /t:c *.jpg ^2^>nul") do del A
Any idea as to how to fix it to run in a BAT file would be very much appreciated.