中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-04 05:25
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » [Help] Asking all the experts for some guidance
Printable Version  668 / 3
Floor1 jufeng Posted 2007-04-16 23:19
初级用户 Posts 20 Credits 66
@echo off
set folder=%date time%
md "f:\%folder%"
copy e:\DataBak\*.* "f:\%folder%"
echo Backup complete.


Is there any error in the above batch file?
Why can't it back up into a folder containing the date and time?
Thanks!!
Floor2 htysm Posted 2007-04-16 23:52
高级用户 Posts 415 Credits 866
You can't use "%date time%.
You can only do it like this: "%date%%time%.
But even then it still won't work; you also have to filter out some characters. You also have to solve the problem of spaces in the filename.
Suggestion: search the forum, there are lots of posts like this.
Floor3 jufeng Posted 2007-04-16 23:58
初级用户 Posts 20 Credits 66
Thanks for the guidance, but how come I can't find it? Could you explain it in more detail? Many thanks from your little brother here!!
I urgently need to use this at work.
Floor4 lililulula Posted 2007-04-17 04:02
中级用户 Posts 138 Credits 302
To remove hyphens use %date:~-=%
To remove spaces, same idea: %date:~ =%
%variable:~str1=str2% replaces str1 with str2, and str2 can be empty

Also, if you only want to display a date like 20070416, you need to extract by position
Under 2000 use %date:~-10,4%%date:~-5,2%%date:~-2%, displayed result: today's date (in 20070416 format)
Under xp use %date:~0,4%%date:~6,2%%date:~-2%

Also, if the OP wants a different date format from what is extracted, you can rewrite it yourself; I won't go into that here
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023