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-06 21:52
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Get the name of the most recently created file View 731 Replies 7
Original Poster Posted 2007-12-05 16:08 ·  中国 上海 联通
新手上路
Credits 8
Posts 3
Joined 2007-12-03 12:09
18-year member
UID 104530
Gender Male
Status Offline
There is a folder with N files in it. The filenames follow a certain pattern, specifically like this: 00001_20071105_023015_890.txt,00002_20071105_032915_561.txt,.....,00012_20071105_233014_743.txt

Is there any way to get the filename of the one that was created most recently?
Floor 2 Posted 2007-12-06 04:04 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Similar questions have already been solved N times, search the forum!!!
Floor 3 Posted 2007-12-06 10:20 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Look into the sorting options of the dir command, for example sorting by time.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 4 Posted 2007-12-06 14:29 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
Originally posted by chenjie9803 at 2007-12-5 16:08:
There is a folder with N files in it. The filenames follow a certain pattern, specifically like this: 00001_20071105_023015_890.txt,00002_20071105_032915_561.txt,.....,00012_20071105_233014_743.txt

Is there any way to get the filename of the one that was created most recently?

I'm a newbie too!
dir *.txt /o:d |find "latest date"
Floor 5 Posted 2007-12-07 16:45 ·  中国 上海 联通
新手上路
Credits 8
Posts 3
Joined 2007-12-03 12:09
18-year member
UID 104530
Gender Male
Status Offline
I did search, and there wasn't what I wanted.

Let me state the full requirement: right now there is a program that generates 1 log file every hour, with one folder per day. Now the requirement is to copy each log to the remote server as soon as it is generated.
Floor 6 Posted 2007-12-07 17:02 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
If that's the case, then a command-line sync tool can completely solve the problem. For example, cmdSync. You only need to use the sync software to periodically synchronize the local log directory to the server through Scheduled Tasks. There's no need to get the latest filename, unless there are stricter or additional requirements.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 7 Posted 2007-12-07 17:13 ·  中国 上海 联通
新手上路
Credits 8
Posts 3
Joined 2007-12-03 12:09
18-year member
UID 104530
Gender Male
Status Offline
Right now I'm just thinking about how to do it with a script........

Just getting the latest filename is enough
Floor 8 Posted 2007-12-08 10:12 ·  中国 山东 济南 移动
系统支持
★★★
Credits 1,011
Posts 435
Joined 2007-02-08 00:00
19-year member
UID 78999
Gender Male
Status Offline
Do you have to use a script?
I'll just tell you directly then.
A script isn't the simplest solution.
You can try a programming language...
Forum Jump: