windows 如何将日期附加到 xcopy 中的目录路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16994879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to append date to directory path in xcopy
提问by user2434611
I do have a xcopy statement in bat file.. would you please help me to append today's date to one of directories in destination xcopy /S /E /I %sourceFolder% "C:\Shared\copy\%destinationFolder%"
我确实在 bat 文件中有一个 xcopy 语句..你能帮我将今天的日期附加到目标 xcopy /S /E /I %sourceFolder% "C:\Shared\copy\%destinationFolder%" 中的目录之一吗
today date is 06072013 so I want my destination look like below
今天的日期是 06072013 所以我希望我的目的地如下所示
C:\Shared\copy-today's date........
C:\Shared\copy-今天的日期........
Thanks
谢谢
回答by foxidrive
This is method of getting a date stamp that doesn't depend on the regional settings. Wmic is available in Windows XP Pro and higher.
这是获取不依赖于区域设置的日期戳的方法。Wmic 在 Windows XP Pro 及更高版本中可用。
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
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 stamp=%YYYY%-%MM%-%DD%
md "C:\Shared\copy-%stamp%"
xcopy here...
回答by Aacini
xcopy /S /E /I %sourceFolder% "C:\Shared\copy-%date:/=%\%destinationFolder%"
回答by Yuriy Galanter
Just use %date%
in your command:
只需%date%
在您的命令中使用:
xcopy /S /E /I %sourceFolder% "C:\Shared\copy\copy-%date%"
Note: this will keep the date in the original format.
注意:这将使日期保持原始格式。
Assuming your local date format is Fri 06/07/2013
you can format it into 06072013
by cutting up the string like this:
假设您的本地日期格式是Fri 06/07/2013
您可以06072013
通过像这样切割字符串来将其格式化:
%date:~4,2%%date:~7,2%%date:~10,4%
So the final command will be:
所以最终的命令将是:
xcopy /S /E /I %sourceFolder% "C:\Shared\copy\copy-%date:~4,2%%date:~7,2%%date:~10,4%"
回答by RGuggisberg
Something like this...
像这样的东西...
for /f "tokens=2-4 delims=/ " %%A in ('echo.%Date%') do set Dest=C:\Shared\copy-%%A%%B%%C
xcopy /S /E /I "%sourceFolder%" "%Dest%"