dir命令:如何仅显示日期创建的文件和其中创建的文件.txt [英] Dir command : How to show only the date created file and created file .txt out of it

查看:324
本文介绍了dir命令:如何仅显示日期创建的文件和其中创建的文件.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 dir / b 仅显示文件名。并且 dir / b / o:-d 仅显示文件名并按最后日期排序。

I know that dir /b shows only the file name. and dir /b /o:-d shows only the file name and sort by it by last date.

是否可以调用dir,仅显示文件创建日期(不显示大小或名称),并从中创建.txt文件?

Is it possible to call dir, that only shows the file created date only (not showing sizes or names) and created a .txt files out of it?

预期结果是这样的

28/06/2019 13:13 
28/06/2019 12:12
28/06/2019 11:11 
....


推荐答案

单独使用 dir 不能做到这一点,但是可以进行后处理它的输出带有 for / f 循环:

You can not do that with dir alone, but you can postprocess it's output with a for /f loop:

for /f "tokens=1,2" %a in ('dir /a-d /o-d') do @echo %a %b|find ":"' 

注意:这是命令行语法。要在批处理文件中使用,请使用 %% 而不是

Note: this is command line syntax. For use in a batch file use %% instead of %

dir / ad 仅显示文件(没有文件夹)。

|找到: 仅显示带有冒号的行(如时间12:34),从而抑制了摘要行。

tokens = 1,2 接受前两个单词(由空格或制表符分隔),因此日期(第一个令牌,转到%a )和时间(第二个令牌,转到%b )。

dir /a-d shows files only (no folders).
|find ":" shows only lines that have a colon (as in time 12:34), suppressing the summary lines.
"tokens=1,2" takes the first two "words" (delimited by spaces or tabs), so the date (first token, goes to %a) and the time (second token, goes to %b).

这篇关于dir命令:如何仅显示日期创建的文件和其中创建的文件.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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