Windows批处理文件来创建文件和日期的CSV列表 [英] Windows batch file to create csv list of file and dates

查看:301
本文介绍了Windows批处理文件来创建文件和日期的CSV列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建生成一个目录中的所有文件三个字段.csv文件Windows批处理文件(减去这个批处理文件!)。

I need to create a Windows batch file that generates a .csv file with three fields for all the files in a directory (minus the batch file itself!).

字段:


  1. 文件名(可以包含逗号!)

  2. 创建日期

  3. 修改日期

请注意,该批处理文件将在目录中运行,并且应该知道生成在当前目录下的文件.csv文件,而应该的不可以列出批处理文件或生成。 csv文件。

Note that the batch file will be run from the directory, and should know to generate the .csv file for the files in the current directory, but should not list the batch file or the generated .csv file.

PowerShell中,VBScript和等等都没有在我的处境是可行的,所以它必须是一个Windows批处理文件。

Powershell, vbscript, and the like are not feasible in my situation, so it has to be a Windows batch file.

编辑:

下面是我已经尝试了两种主要的方法。

Here are the two main approaches that I have tried.

第一次尝试:的我已经试过了单纯的文件名分成temp1.tmp,与创建的时间戳为temp2.​​tmp文件列表,并与修改后的文件列表时间戳为temp3.tmp。

First attempt: I've tried separating the bare file names into "temp1.tmp", the file list with the created timestamps into "temp2.tmp", and the file list with the modified timestamps into "temp3.tmp".

DIR /B /A:-D-H | FIND /V "Print Files.bat" | FIND /V "File List" | FIND /V "temp"  > "temp1.tmp"
DIR /A:-D-H /T:C | FIND /V "Print Files.bat" | FIND /V "File List" | FIND /V "temp"  > "temp2.tmp"
DIR /A:-D-H /T:W | FIND /V "Print Files.bat" | FIND /V "File List" | FIND /V "temp"  > "temp3.tmp"

MORE +5 "temp2.tmp" > "temp4.tmp"
COPY /Y "temp4.tmp" "temp2.tmp"
MORE +5 "temp3.tmp" > "temp4.tmp"
COPY /Y "temp4.tmp" "temp3.tmp"
DEL /F/Q "temp4.tmp"

不过,这种方法的问题是,我无法弄清楚如何从多个文件一次读取行。下面是我发现的最接近,但也仅仅是从一个文件:

But the problem with this approach is that I cannot figure out how to read lines from more than one file at a time. Here is the closest that I have found, but it is only from one file:

FOR /F "delims=" %%i IN (temp1.tmp) DO (
    ECHO."%%i" >> "File List.csv"
)

第二次尝试:的我已经尝试使用临时文件避免,但无济于事。

Second attempt: I've tried avoiding using temporary files, but to no avail.

FOR %%i IN (*.*) DO @ECHO "%%~ni%%~xi",%%~ti >> "File List.csv"

与该第二种方法的问题是,它不排除批处理文件名,和它不提供文件创建时间戳。

The problem with this second approach is that it doesn't exclude the batch file name, and it doesn't provide the file creation timestamp.

有没有一种解决方案,使这两种工作对我来说,或者说我还没有尝试过的方法?

Is there a solution to make either of these work for me, or an approach that I haven't tried yet?

推荐答案

试试这个:

@ECHO OFF &SETLOCAL
(FOR /f "delims=" %%a IN ('dir /b /a-d') DO (
    FOR /f "tokens=1-3*" %%x IN ('dir /a-d /tc "%%~a"^|findstr "^[0-9]"') DO (
        ECHO "%%a",%%~ta,%%x %%y %%z
    )
))>DIR.csv
TYPE DIR.csv

这篇关于Windows批处理文件来创建文件和日期的CSV列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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