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,172 Replies 33
Floor 16 Posted 2006-10-15 10:55 ·  中国 上海 嘉定区 电信
初级用户
Credits 30
Posts 14
Joined 2006-10-15 08:13
19-year member
UID 65835
Status Offline
Moderator qwe1234567, why did the program code you posted earlier under the 2000 environment disappear?
Floor 17 Posted 2006-10-15 10:56 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
set a=%date:~4,4%%date:~9,2%%date:~12,2%@%time:~0,2%%time:~3,2%%time:~6,2%
ren *.txt *%a%.txt

If you want to modify the TEST.TXT file, you just need to replace *.txt with test.txt. If you put this file in the folder where you need to change the file names, you can omit the path, and you can also change all TXT file names!

[ Last edited by qwe1234567 on 2006-10-15 at 10:57 ]
Floor 18 Posted 2006-10-15 11:00 ·  中国 上海 嘉定区 电信
初级用户
Credits 30
Posts 14
Joined 2006-10-15 08:13
19-year member
UID 65835
Status Offline
Thank you very much. I will see what other special functions the supervisor needs on Monday.
Floor 19 Posted 2006-10-15 11:00 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Refer to the modification by moderator qwe1234567 for 2K:

XP
@echo off
set datetime=%~n1%date:~0,4%%date:~5,2%%date:~8,2%@%time:~0,2%%time:~3,2%%time:~6,2%%~x1
copy %1 %datetime%

2K
@echo off
set datetime=%~n1%date:~4,4%%date:~9,2%%date:~12,2%@%time:~0,2%%time:~3,2%%time:~6,2%%~x1
copy %1 %datetime%

The operation method is: bat *.txt (with extension)
Floor 20 Posted 2006-10-15 12:18 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Integrated with zxcv, qwe1234567 moderators, DOS.BAT content
@echo off
if "%1"=="/?" echo Rename the target file name to "source file name + current date + @ + time" &&echo.&&echo Syntax: DOS filename &&PING/n 4 127.1>NUL &&exit
if "%1"=="" echo Rename the target file name to "source file name + current date + @ + time" &&echo.&&echo Syntax: DOS filename &&PING/n 4 127.1>NUL &&exit
ver|find /i "xp">nul
if not errorlevel 1 set datetime=%~n1%date:~0,4%%date:~5,2%%date:~8,2%@%time:~0,2%%time:~3,2%%time:~6,2%%~x1
ver|find /i "2000">nul
if not errorlevel 1 set datetime=%~n1%date:~4,4%%date:~9,2%%date:~12,2%@%time:~0,2%%time:~3,2%%time:~6,2%%~x1
if "%datetime%"=="" echo This program must run on Windows xp or Windows 2000 system &&ping/n 4 127.1>nul &&exit
echo %1 %datetime%
第一高手 第二高手

Floor 21 Posted 2006-10-15 13:00 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
On Error Resume Next

Set objArgs = WScript.Arguments
If objArgs.Count < 1 Then
WScript.Echo "Drag files to this file with mouse or run with arguments!"
WScript.Quit
End If

For Each strFile In objArgs
strNewFile = Mid(strFile,1,InStrRev(strFile,".") _
- 1) & Replace(Date,"-","") & "@" _
& Replace(Time,":","") & _
Mid(strFile,InStrRev(strFile,".") )
If Len(Trim(strNewFile)) = 0 Then
strNewFile = strFile & Replace(Date,"-","") & _
"@" & Replace(Time,":","")
End If
ReName strFile , strNewFile
Next


Sub ReName (strFile,strNewFile)
WScript.Echo strFile & vbLf & strNewFile
CreateObject("Scripting.FileSystemObject") _
.MoveFile strFile,strNewFile
End Sub
```
Copy to SendTo, then select all the files to be modified and send to... That's it.
Or call with multiple parameters in bat, you can change the first line of the ReName procedure from vblf to "," to display the change details for forming a log.
Floor 22 Posted 2006-10-15 22:51 ·  中国 湖北 武汉 电信
初级用户
Credits 28
Posts 11
Joined 2006-10-12 21:18
19-year member
UID 65492
Status Offline
I only have less than 11:00 AM here, why are you all at 2006-10-15 13:00, Moderator, is there a problem with the server time?
Floor 23 Posted 2006-10-16 22:53 ·  中国 上海 嘉定区 电信
初级用户
Credits 30
Posts 14
Joined 2006-10-15 08:13
19-year member
UID 65835
Status Offline
Dear all experts,

Just now, my supervisor told me that it was tested in the 2000 server en environment. I copied the date and time.

C:\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: 10:44:17.73
Enter the new time:

fastslz, can you log in to MSN? I want to ask you some questions, thank you very much
Floor 24 Posted 2006-10-16 23:04 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
```
set a=%date:~6,4%%date:~0,2%%date:~3,2%@%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%
ren *.txt *%a%.txt
```
Floor 25 Posted 2006-10-16 23:13 ·  中国 山西 运城 电信
中级用户
★★
Credits 241
Posts 131
Joined 2005-09-28 19:01
20-year member
UID 42920
Gender Male
Status Offline
@echo off
set /p yy=Path of the file to be processed:
set /p uu=Name of the file to be processed:
for /F "tokens=1-3 delims=/- " %%A in ('date/T') do set DATE=%%A%%B%%C
for /F "tokens=1-2 delims=/: " %%A in ('time/T') do set TIME=%%A%%B
for %%i in (%yy%:\%uu%) do copy %%i %yy%:\%%~ni%DATE%@%TIME%.txt

Borrowed fastslz's code, but with the above几句 added, it can process files on any drive letter! Also: When displaying this sentence, do not enter a colon after the drive letter!
房东说:这娃是个好孩子!
Floor 26 Posted 2006-10-17 00:01 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Originally posted by samzj at 2006-10-16 22:53:
Hello everyone
Just now, my supervisor told me that the test was carried out in the 2000 server en environment. I copied the date and time.
C:\Documents and Settings\Administrator>date
The current date is: 10/16/2006 Mon
Enter t ...


The time sequence in the English version is different.
If I replace
for /F "tokens=1-3 delims=/- " %%A in ('date/T') do set DATE=%%A%%B%%C

in my code with
for /F "tokens=1-3 delims=/- " %%A in ('date/T') do set DATE=%%C%%B%%A

that is, just change the order, which is easy to grasp.
第一高手 第二高手

Floor 27 Posted 2006-10-17 01:09 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
The best for such a problem

echo %time%
echo %date%

Post these two displays
Floor 28 Posted 2006-10-17 02:21 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
```batch
@echo off
set /p lj=Path of the file to be processed:
set /p wjm=Name of the file to be processed:
copy %lj%%wjm% %lj%%wjm%%date:~10,4%%date:~4,2%%date:~7,2%@%time:~0,2%%time:~3,2%%time:~6,2%.txt
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
+4 2006-10-17 04:47
Floor 29 Posted 2006-10-17 03:58 ·  中国 上海 嘉定区 电信
初级用户
Credits 30
Posts 14
Joined 2006-10-15 08:13
19-year member
UID 65835
Status Offline
Thanks to everyone's enthusiastic help~~~~
Today, under the remote guidance of moderator qwe1234567, this problem was finally temporarily solved.
Test environment: 2000 server en

C:\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

Finally successful, thank you all who posted to help!!!!
Floor 30 Posted 2006-10-17 03:59 ·  中国 上海 嘉定区 电信
初级用户
Credits 30
Posts 14
Joined 2006-10-15 08:13
19-year member
UID 65835
Status Offline
And also need to thank fastslz for the patient explanation~~~~~~ and so on and so forth
Forum Jump: