如何使用批处理文件重命名现有文件以进行备份?

时间:2008-11-15 10:32:02

标签: batch-file windows-xp rename

pkzip25 -add=all -dir=current -silent -locale -exclude=DistData.zip -exclude=extract.bat -exclude=run.bat -exclude=pkzip25.exe -exclude=extracted.txt -exclude=zipped.txt -exclude=.\STORE DistData.zip *.*
pkzip25 -view -directories DistData.zip >zipped.txt

copy DistData.zip ..\BKX\DistData_1.zip
cd ..\BKX
rename DistData_1.zip DistData_2.zip 
rename DistData_2.zip DistData_3.zip
rename DistData_3.zip DistData_4.zip
rename DistData_4.zip DistData_5.zip

1 个答案:

答案 0 :(得分:2)

rename DistData_1.zip DistData_2.zip 
rename DistData_2.zip DistData_3.zip
rename DistData_3.zip DistData_4.zip
rename DistData_4.zip DistData_5.zip

错了,您必须使用相反的顺序并先删除最后一个:

del DistData_5.zip
rename DistData_4.zip DistData_5.zip
rename DistData_3.zip DistData_4.zip
rename DistData_2.zip DistData_3.zip
rename DistData_1.zip DistData_2.zip 

也许还可以移动DistData.zip而不是复制,所以如果你创建一个新的zip文件就不存在。

move DistData.zip ..\BKX\DistData_1.zip

但我不知道这是不是你的问题。

编辑: 如果你想保留5个zipfiles(而不是4个),我建议如下:

del DistData.zip >NUL 2>&1
pkzip25 -add=all -dir=current -silent -locale -exclude=DistData.zip -exclude=extract.bat -exclude=run.bat -exclude=pkzip25.exe -exclude=extracted.txt -exclude=zipped.txt -exclude=.\STORE DistData.zip *.*
pkzip25 -view -directories DistData.zip >zipped.txt

move DistData.zip ..\BKX
cd ..\BKX
del DistData_5.zip
rename DistData_4.zip DistData_5.zip
rename DistData_3.zip DistData_4.zip
rename DistData_2.zip DistData_3.zip
rename DistData_1.zip DistData_2.zip 
rename DistData.zip DistData_1.zip 

这样你总有5个备份副本。