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-01 14:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask experts: Regarding the problem of modifying file names...... Thank you View 1,891 Replies 7
Original Poster Posted 2006-02-20 10:44 ·  中国 江苏 南京 秦淮区 电信
初级用户
Credits 92
Posts 28
Joined 2005-11-23 12:38
20-year member
UID 45780
Gender Male
From nanjin
Status Offline
Proposal 1: How to use the current machine time as the file name for the created document???
Proposal 2: The existing program automatically generates a document with the current time (numbers) as the file name (I don't know)... I wonder if I can create a batch program that, after execution, copies the document within 10 seconds, but extends the time file name by 10 seconds. For example, 20051030105022.TXT is copied to another 20051030105032.TXT... Thank you.
.. Please note that the file name is time.

Or copy the document when it is 10 seconds after the document is created but use the current time as the file name.

Thank you all for your concern.
Looking forward to the experts' explanations.
Floor 2 Posted 2006-02-20 13:11 ·  中国 广东 广州 天河区 电信
中级用户
★★
Credits 466
Posts 237
Joined 2005-10-12 20:53
20-year member
UID 43413
Status Offline
I. 1. File names can use %UserName% (valid only for Win2000, XP systems)
Floor 3 Posted 2006-02-20 15:09 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re kumho:

From your description, it seems you want to name files in a compact numeric format of date + time, and copy a file with the original file name and the time 10 seconds after the creation time in the same format. I guess your application is NT CMD. My algorithm is basically as follows. Friends who are willing to implement and other algorithms, you might as well put forward your own opinions.

First, use for /f to splice the environment variables %date% %time% provided by the system, and need to determine and modify the display format of date and time (such as the problem of 0 prefix and 12/24 hour system).

Second, use choice / ping / for+set+if to delay for 10 seconds, and copy a file renamed with the current date and time.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 4 Posted 2006-02-21 18:56 ·  中国 上海 闵行区 电信
中级用户
★★
大师兄
Credits 377
Posts 99
Joined 2005-08-26 07:37
20-year member
UID 41945
Status Offline
Under XP, use GNU date:

for /f "tokens=*" %i in ('.\date -R') do @for /f "tokens=*" %j in ('.\date -d "%i" +%Y%m%d%H%M%S') do @the_command>%j.txt 2>NUL&for /f "tokens=*" %k in ('.\date -d "%i 10 sec" +%Y%m%d%H%M%S') do @copy %j.txt %k.txt
Floor 5 Posted 2006-03-04 11:55 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
Truly a master among masters.
Floor 6 Posted 2006-03-04 13:05 ·  中国 北京 平谷区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
The first situation is that the computer's name is used as the file name. The environment variable we need to use is %comptername%.

The second situation, let's take a look at the code. The time is inaccurate, and the others should meet your requirements.

@echo off
set /p i=Enter the full path of the file you are going to copy:
set /p u=Enter the target folder path:
:backup
ping 1.1.1.1 -n 20 -w 400>nul
echo %date%%time%>1.txt
for /f "tokens=2,3,4,5,6* delims=-:. " %%i in (1.txt) do copy %i% %u%\%%i%%j%%k%%l%%m%%n.txt
echo Backing up once... ...
goto backup
Floor 7 Posted 2006-03-04 14:15 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
@echo off
set /a 日期 = %date:~0,4%%date:~5,2%%date:~8,2%
set /a 时间 = %time:~0,2%%time:~3,2%%time:~6,2%
echo 欢迎来到中国DOS联盟! >%日期%%时间%.txt

cls
echo Press any key to start copying files...
pause>nul

:copy
copy %日期%%时间%.txt %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.txt >nul
set /a num = %num% + 1
set string=File has been copied %num% times, click OK to cancel...

msg %username% /time:10 /w %string% >nul && set /a hflag = %time:~6,1% && set /a lflag = %time:~7,1%
set /a new = %time:~6,2%
if %hflag% == 5 set /a hflag = 0 && set /a new = %new% + 10
set /a old = %hflag%%lflag%
set /a flag = %new% - %old%
if %flag% LSS 10 goto :eof
goto copy

Run under XP, need to enable the TermService service (usually enabled by default), if not, you can modify: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermService the START key...
After running, it will first generate the file required in requirement 1, then prompt you to press any key to start copying files (requirement 2). If you press Enter, a dialog box will pop up to prompt you with information about the file being copied, such as time (in the title), number of times, etc. If you don't want to copy, just click OK, and the command line will exit automatically.
Floor 8 Posted 2006-03-04 15:14 ·  中国 江苏 南京 电信
初级用户
Credits 92
Posts 28
Joined 2005-11-23 12:38
20-year member
UID 45780
Gender Male
From nanjin
Status Offline
Thanks, fellow seniors, the problem is solved
Forum Jump: