开发者

How to get the Last Modified date of all files in a folder using Batch

Suppose i have a folder which contains 5 files. I want to run a b开发者_StackOverflow中文版atch script which outputs all the filenames in the folder along with the last modified dates. The output has to be written as a text file.

The output should be as follows:

  • Sample1.xls 4/7/2011
  • Sample2.xls 3/6/2011
  • Sample3.xls 5/4/2011
  • Sample4.xls 2/4/2011
  • Sample5.xls 6/2/2011


From the commandline:

for /f %a in ('dir /b') do @echo %a %~ta

This outputs:

D:\temp\modtime>dir
 Volume in drive D is Data1
 Volume Serial Number is 925B-DC37

 Directory of D:\temp\modtime

06/28/2012  05:03 PM    <DIR>          .
06/28/2012  05:03 PM    <DIR>          ..
06/28/2012  05:02 PM                 2 a.txt
06/28/2012  05:03 PM                 2 b.txt
               2 File(s)              4 bytes
               2 Dir(s)  1,485,646,065,664 bytes free

D:\temp\modtime>for /f %a in ('dir /b') do @echo %a %~ta
a.txt 06/28/2012 05:02 PM
b.txt 06/28/2012 05:03 PM

Make the % into %% to put it in a batch file. If you don't need the times, you can post-process to get rid of them.


You should use dir command i think dir . /o-d have look to this linke MSDOS DirCommand

also you can create a text file and put the command in the file and save it as .bat file

if you read the link you will see there are many option check this one

dir *.* /o-n-d /b
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜