帮助编写DOS脚本以获取最新目录的名称(创建时间) [英] Help writing DOS script to get get name of the most recent directory (time created)
问题描述
我需要一些帮助来获取DOS脚本中最新目录的名称。
Hey Guys, I need some help in getting the name of the most recent directory in a DOS script.
我找到了一些有关获取最新文件的信息,但我无法在目录上使用它。
I have found some information on getting the most recent file which works but I cannot get this to work on directories.
例如,这是我的目录:
drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:34 _200903_V20
drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:35 _200904_V21
drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:36 _200905_V22
drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:38 _200906_V23
我需要我的脚本来为我返回最新目录(V23)。然后,我将进入该目录并从其中复制一个文件。
I need my script to return me the most recent directory (V23). I will then cd into that directory and copy a file out of it.
谢谢您的帮助!
推荐答案
此处是指向找到最新文件的两个脚本的链接。我想第二个已经完全可以满足您的需求,但是我敢肯定,您可以修改其中一个来满足您的需求。我只是用Google搜索找到最近的文件dos批处理文件 并立即找到它。
Here is a link to two scripts that find the most recent file. I think the second one already does exactly what you want, but you can modify one of them to do what you need, I'm pretty sure. I just googled "find most recent file dos batch file" and found it immediately.
经过编辑以添加适用于目录的脚本:
Edited to add a script that works with directories:
@echo off
for /f "delims=" %%x in ('dir /od /b *.*') do set recent=%%x
echo %recent%
输出:
C:\> recent.bat
recent.bat
C:\> mkdir newdir
C:\> recent.bat
newdir
看起来像在这里工作。
这篇关于帮助编写DOS脚本以获取最新目录的名称(创建时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!