![]() |
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-23 16:42 |
47,812 topics / 349,917 posts / today 0 new / 48,274 members |
| DOS批处理 & 脚本技术(批处理室) » Ask experts: Regarding the problem of modifying file names...... Thank you |
| Printable Version 2,043 / 7 |
| Floor1 kumho | Posted 2006-02-20 10:44 |
| 初级用户 Posts 28 Credits 92 From nanjin | |
|
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. |
|
| Floor2 Scott0902 | Posted 2006-02-20 13:11 |
| 中级用户 Posts 237 Credits 466 | |
|
I. 1. File names can use %UserName% (valid only for Win2000, XP systems)
|
|
| Floor3 willsort | Posted 2006-02-20 15:09 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. |
|
| Floor4 tigerpower | Posted 2006-02-21 18:56 |
| 中级用户 Posts 99 Credits 377 | |
|
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 |
|
| Floor5 htysm | Posted 2006-03-04 11:55 |
| 高级用户 Posts 415 Credits 866 | |
|
Truly a master among masters.
|
|
| Floor6 bagpipe | Posted 2006-03-04 13:05 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
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 |
|
| Floor7 3742668 | Posted 2006-03-04 14:15 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
@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. |
|
| Floor8 kumho | Posted 2006-03-04 15:14 |
| 初级用户 Posts 28 Credits 92 From nanjin | |
|
Thanks, fellow seniors, the problem is solved
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |