使用批处理文件的一系列文件的打开其中一个 [英] Open one of a series of files using a batch file

查看:80
本文介绍了使用批处理文件的一系列文件的打开其中一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最多有基于此结构的4个文件(注意prefixes的日期)

I have up to 4 files based on this structure (note the prefixes are dates)


  • 0830filename.txt

  • 0907filename.txt

  • 0914filename.txt

  • 0921filename.txt

我想打开最近的一次(0921filename.txt)。我怎么能做到这一点在批处理文件?

I want to open the the most recent one (0921filename.txt). how can i do this in a batch file?

感谢。

推荐答案

此方法使用的实际文件的修改日期,要弄清楚哪一个是最新的文件:

This method uses the actual file modification date, to figure out which one is the latest file:

@echo off
for /F %%i in ('dir /B /O:-D *.txt') do (
    call :open "%%i"
    exit /B 0
)
:open
    start "dummy" "%~1"
exit /B 0

这个方法,但是,在选择字母顺序的最后一个文件(或第一位的,在反向字母顺序),因此,如果文件名是一致的 - 它会工作:

This method, however, chooses the last file in alphabetic order (or the first one, in reverse-alphabetic order), so if the filenames are consistent - it will work:

@echo off
for /F %%i in ('dir /B *.txt^|sort /R') do (
    call :open "%%i"
    exit /B 0
)
:open
    start "dummy" "%~1"
exit /B 0

您居然要选择哪种方法更适合您。

You actually have to choose which method is better for you.

这篇关于使用批处理文件的一系列文件的打开其中一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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