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-02 10:22
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » The task assigned by the supervisor is to be handed in on Monday. Hope experts can help~DOS.BAT file renaming application View 4,173 Replies 33
Floor 31 Posted 2006-11-06 23:41 ·  中国 上海 嘉定区 电信
初级用户
Credits 30
Posts 14
Joined 2006-10-15 08:13
19-year member
UID 65835
Status Offline
Moderator qwe1234567, there is a problem when using it. When the time is from 00:00 to 09:59, an error occurs and no result can be obtained, while other time periods are normal... The supervisor told me that it might be a problem with the first 0. Is there probably a solution...

Friends who know, please also explain..

:\Documents and Settings\Administrator>date
The current date is: 10/16/2006 Mon
Enter the new date: (mm-dd-yy)

C:\Documents and Settings\Administrator>time
The current time is: 15:56:45.35
Enter the new time:


set a=%date:~10,4%%date:~4,2%%date:~7,2%@%time:~0,2%%time:~3,2%%time:~6,2%
copy c:\test.bat test%a%.bat
Floor 32 Posted 2006-11-06 23:57 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
The `%time%` method has no leading zero from 00:00 to 09:59.

Using delayed expansion:

```batch
setlocal EnableDelayedExpansion
set time$=%time:~0,8%&&set time$=!time$::=!&&set time$=!time$: =0!
set a=%date:~10,4%%date:~4,2%%date:~7,2%@%time$%
copy c:\test.bat test%a%.bat
```

Without using delayed expansion:
```batch
set time$=%time:~0,8%
set time$=%time$::=%
set time$=%time$: =0%
set a=%date:~10,4%%date:~4,2%%date:~7,2%@%time$%
copy c:\test.bat test%a%.bat
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +2 2006-11-07 00:37
Floor 33 Posted 2006-11-07 00:32 ·  中国 上海 嘉定区 电信
初级用户
Credits 30
Posts 14
Joined 2006-10-15 08:13
19-year member
UID 65835
Status Offline
zxcv: Thanks a million, it worked without using the delay variable with the second one...
Floor 34 Posted 2006-11-07 04:28 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Principle:
set time$=%time:~0,8%
Get the first 8 digits of %time% ("9:59:45.35"), which is "9:59:45" (there is a space if the first digit is less than 10)
set time$=%time$::=%
Remove the colon ":" in "9:59:45" to get "95945"
set time$=%time$: =0%
Replace the space in "95945" with "0" to get "095945"
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +2 2006-11-07 04:37
Forum Jump: