如何获取Windows脚本中最新(按创建时间)目录的名称? [英] How to get get name of the most recent (by creation time) directory in a Windows script?

查看:54
本文介绍了如何获取Windows脚本中最新(按创建时间)目录的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在获取Windows脚本中最新目录的名称时,我需要一些帮助.

I need some help in getting the name of the most recent directory in a Windows 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

看起来像在这里工作.

这篇关于如何获取Windows脚本中最新(按创建时间)目录的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆