中国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-09-24 03:13
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » The task assigned by the supervisor is to be handed in on Monday. Hope experts can help~DOS.BAT file renaming application
Printable Version  4,546 / 33
Floor31 samzj Posted 2006-11-06 23:41
初级用户 Posts 14 Credits 30
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
Floor32 zh159 Posted 2006-11-06 23:57
金牌会员 Posts 1,467 Credits 3,687
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
```
Floor33 samzj Posted 2006-11-07 00:32
初级用户 Posts 14 Credits 30
zxcv: Thanks a million, it worked without using the delay variable with the second one...
Floor34 zh159 Posted 2006-11-07 04:28
金牌会员 Posts 1,467 Credits 3,687
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"
Prev  1 2 3
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023