如何在批处理

时间:2015-09-02 07:10:35

标签: batch-file

这里的第一个线程,我需要知道如何“复制但保留两个文件”我在启动时使用批处理文件复制的目录。这是我的代码:

@ECHO OFF    
color 1F    
cls    
:choice    
echo Do you want to backup saves?    
set /P c=[Y/N]?     
if /I "%c%" EQU "Y" goto :y    
if /I "%c%" EQU "N" goto :somewhere_else    
goto :choice    
:y   
cls
title Making Backup of saves...    
XCOPY C:\Users\Jaydon\AppData\Roaming\.minecraft\VersionFiles\1.9\saves\*     
C:\Backupof1.9\ /i /s /r /y    
cls    
:done    
echo Done!    
set /P c=Press a key to exit.    
if /I "%c%" EQU "" goto :doneexit    
exit
:doneexit    
cls    
exit       
pause     
exit    
cls    
:somewhere_else    
cls    
echo You have chosen to exit!    
ping 127.0.0.1 -n 5 > nul    
exit    
cls

我需要复制以下所有文件夹和文件:

"C:\Users\Jaydon\AppData\Roaming\.minecraft\VersionFiles\1.9\saves\*" 

"C:\Backupof1.9\"

到目前为止,这只是压倒它,这很好。但是它创建一个新文件夹或添加(1),2,3,4,5等等会很高兴。

任何帮助表示赞赏,jjws600

1 个答案:

答案 0 :(得分:0)

这应该将您的保存备份到您请求的位置,但使用备份的日期和时间 - 并在列表中正确排序,以便最新的文件夹始终位于底部。

它假定您有权写入文件夹所在的c:驱动器的根目录。

@echo off
rem The four lines below will give you reliable YY DD MM YYYY HH Min Sec MS variables in XP Pro and higher.

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" & set "MS=%dt:~15,3%"
set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%" & set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%-%MS%"

echo datestamp: "%datestamp%"
echo timestamp: "%timestamp%"
echo fullstamp: "%fullstamp%"
if not defined fullstamp goto :EOF

set "datafolder=C:\Users\Jaydon\AppData\Roaming\.minecraft\VersionFiles\1.9\saves"
set "backupfolder=C:\Backupof1.9\%fullstamp%"

set switches=/r:0 /w:0 /mir /ns /nc /ndl /np /njh /njs

robocopy %switches% "%datafolder%" "%backupfolder%"

pause