我创建了一个批处理文件,它将一个文件夹的数据复制到另一个文件夹中。但复制后我想把naem作为文件夹名称。我无法做到。请提出你的建议。抱歉改变了这个问题。但现在我需要这个。
这是我的代码。
@echo off
:: variables
echo Backing up file
set /P source=Enter source folder:
set /P destination=Enter Destination folder:
set listfile=xcopy /L
set xcopy=xcopy /S/E/V/Q/F/H
%listfile% %source% %destination%
echo files will be copy press enter to proceed
pause
%xcopy% %source% %destination%
pause
答案 0 :(得分:0)
我认为(根据评论)您想要将日期和时间附加到目标文件夹。如下所示,使用一个set命令将日期和时间转换为可在文件夹名称(explained here)中使用的格式,另一个用于设置新文件夹名称。在xcopy之后,使用move命令重命名该文件夹。 (参见引用的关于在%datename%文件夹周围保留引号的来源。)
@echo off
echo Backing up file
:: variables
set /P source=Enter source folder:
set /P destination=Enter Destination folder:
:: This converts the date and time environmental variables to a
:: format you can use in a folder name.
set dt=%date:~7,2%-%date:~4,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%
:: Set the new folder name appending the dt variable.
:: %destination% needs to be a folder name only, not a full path
set datename=%destination%%dt%
set listfile=xcopy /L
set xcopy=xcopy /S/E/V/Q/F/H
%listfile% %source% %destination%
echo files will be copy press enter to proceed
pause
%xcopy% %source% %destination%
pause
:: This renames %destination% to the %datename% you set.
:: Keep quote marks. %datename% can have a space depending on time
MOVE "%destination%" "%datename%"