So, here is my simple batch file for backing up my files onto a USB drive (drive F. It checks to see how many folders there are and if there are more than 18, it deletes the oldest ones, regardless of how many more than 18 there are. Although, when it's working properly, there is never more than one to delete, but I have tested it by creating say 25 folders, and it will delete all but 18. Then it creates a new directory with the current date and copies all my files into it. The batch file was working just fine, every day, for months. But, now it doesn't.
I get an error that says "%%a was unexpected at this time." I do know it's the first "%%a" after the "skip=18 tokens=* delims= " section that it's complaining about, but I don't know why, especially considering it was working for so long.
Anyone have any ideas? Thanks in advance!
--------------------------Batch File--------------------------
for /f "skip=18 tokens=* delims= " %%a in ('dir F:\ /ad /b /o-d') do (rmdir /s /q F:\%%a)
rmdir /s /q F:\$RECYCLE.BIN
xcopy /C /E /H /I /K /R /Y C:\Files F:\%date:~-4,4%"-"%date:~-10,2%"-"%date:~-7,2%
I get an error that says "%%a was unexpected at this time." I do know it's the first "%%a" after the "skip=18 tokens=* delims= " section that it's complaining about, but I don't know why, especially considering it was working for so long.
Anyone have any ideas? Thanks in advance!
--------------------------Batch File--------------------------
for /f "skip=18 tokens=* delims= " %%a in ('dir F:\ /ad /b /o-d') do (rmdir /s /q F:\%%a)
rmdir /s /q F:\$RECYCLE.BIN
xcopy /C /E /H /I /K /R /Y C:\Files F:\%date:~-4,4%"-"%date:~-10,2%"-"%date:~-7,2%