There are 3 (maybe 4) errors in the file.
- _wrpath has C:\ twice.
- You added the /F switch to the For loop in my original code. It shouldn't be there
- You don't have the _wrpath variable to find the 7z file, so unless you are in the 7zip folder, or it's on your path, it won't work
- The lines in Squashman's code are on separate lines for a reason.
Did you actually put them on one line, or is that just the way it got posted?
If you want to combine them, you have to use the & symbol.
The main problem is the
/F switch. With that switch, wildcards are not allowed in a fileset (they can be used in a command), so it tries to open a file with an
* in the name. As that's not a valid character for a file name, it fails, giving this error:
The system cannot find the file C:\Temp\Backups\sumtotal\*.bak.
The next line in the error is not a normal message from the Del command, at least on Win2K, XP, Vista, and Win7.
Do you have an echo statement you didn't post that is displaying this:
Deleting Bak files from: C:\Temp\Backups\sumtotal.
On my system, it never tries to execute the
Del command. I'm not sure why it is executing it on yours.
Quote:
Originally Posted by pma083 Code:
@echo off
setlocal
set _source=C:\Temp\Backups\sumtotal
set _dest=C:\Temp\Backups\sumtotal
set _wrpath=C:\C:\Program Files\7-Zip
if NOT EXIST %_dest% md %_dest%
for /f %%I in (%_source%\*.bak) do (7z a "%_dest%\%%~nI.7z" "%%I" del "%%I")
pause |
So use this:
Code:
@echo off
setlocal
set _source=C:\Temp\Backups\sumtotal
set _dest=C:\Temp\Backups\sumtotal
set _wrpath=C:\Program Files\7-Zip
if NOT EXIST %_dest% md %_dest%
for %%I in (%_source%\*.bak) do (
"%_wrpath%\7z" a "%_dest%\%%~nI.7z" "%%I"
del "%%I"
)
pause
If you want the For statement all on one line, use this (note the ampersand, and no parentheses):
Code:
@echo off
setlocal
set _source=C:\Temp\Backups\sumtotal
set _dest=C:\Temp\Backups\sumtotal
set _wrpath=C:\Program Files\7-Zip
if NOT EXIST %_dest% md %_dest%
for %%I in (%_source%\*.bak) do "%_wrpath%\7z" a "%_dest%\%%~nI.7z" "%%I" & del "%%I"
pause
With either of these, %%I does contain the full path, so you don't need to add it to the Del command.
HTH
Jerry