Hi, I have an easy question. I'm using below in a batch file:
forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d -11 /c "cmd /c del @file"
The "-11" tells it to erase files older than 11 days.
since this is one of many command lines I have, i'd like one variable to replace the -11...something like:
SET l_days = -1
forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d "%l_days%" /c "cmd /c del @file"
But, this is not the correct syntax...please advise, and thanks!
DOS batch file variable
Moderator: DosItHelp
Re: DOS batch file variable
Remove the double quotes that you added and try it.
Re: DOS batch file variable
Trying below:
SET l_days = "-1"
forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d %l_days% /c "cmd /c del @file"
Gets error: (I should have noted I had already tried this before my post)
E:\APPS\BATCH_JOBS>forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d /c "cm
d /c del @file"
ERROR: Invalid syntax. Value expected for '/d'.
Type "FORFILES /?" for usage.
SET l_days = "-1"
forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d %l_days% /c "cmd /c del @file"
Gets error: (I should have noted I had already tried this before my post)
E:\APPS\BATCH_JOBS>forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d /c "cm
d /c del @file"
ERROR: Invalid syntax. Value expected for '/d'.
Type "FORFILES /?" for usage.
Re: DOS batch file variable
Hi,
I have already tried it without the quotes before making this post:
SET l_days = "-1"
forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d %l_days% /c "cmd /c del @file"
ERROR: Invalid syntax. Value expected for '/d'.
Type "FORFILES /?" for usage.
I have already tried it without the quotes before making this post:
SET l_days = "-1"
forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d %l_days% /c "cmd /c del @file"
ERROR: Invalid syntax. Value expected for '/d'.
Type "FORFILES /?" for usage.
Re: DOS batch file variable
You put quotes back in it, in a different place.
Re: DOS batch file variable
? are you saying that I "did"",,, or that I should? either way, I've tried every variations of "% and @...not just what I am posting on here. I get same error.
can u give me an example of what it should be?
thanks
can u give me an example of what it should be?
thanks
Re: DOS batch file variable
I wasn't paying close enough attention myself - I failed to see where you had a space in the environment variable name.
Try this:
This term SET l_days = -1 is an environment variable called %SET l_days % with that extra trailing space, and it sets the contents of the environment variable to " -1" sans the quotes. That extra leading space is in the variable data itself too.
I saw the extra space that was before the minus sign but I didn't comment because it didn't affect the position it was being used in.
I hope that works for you...
Time for a snooze...
Try this:
Code: Select all
SET l_days=-1
forfiles.exe /p "B:\iCamSource_videos" /s /m *.jpg /d %l_days% /c "cmd /c del @file"
This term SET l_days = -1 is an environment variable called %SET l_days % with that extra trailing space, and it sets the contents of the environment variable to " -1" sans the quotes. That extra leading space is in the variable data itself too.
I saw the extra space that was before the minus sign but I didn't comment because it didn't affect the position it was being used in.
I hope that works for you...
Time for a snooze...
Re: DOS batch file variable
Thanks, it all works very well...much appreciated!