China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-04 06:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Asking all the experts for some guidance View 669 Replies 3
Original Poster Posted 2007-04-16 23:19 ·  中国 广西 电信
初级用户
Credits 66
Posts 20
Joined 2006-05-30 10:07
20-year member
UID 56242
Status Offline
@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!!
Floor 2 Posted 2007-04-16 23:52 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
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.
Floor 3 Posted 2007-04-16 23:58 ·  中国 广西 电信
初级用户
Credits 66
Posts 20
Joined 2006-05-30 10:07
20-year member
UID 56242
Status Offline
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.
Floor 4 Posted 2007-04-17 04:02 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
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
Forum Jump: