2

We have a file repository containing code files *.sql; *.xep; *.dll; *.aspx; *.gif that you are going to submit to Production pretty soon. In this repository we have the main folders which contain the most recent code files to go to PROD, but we also have all the Change Folders that where submitted to PRE-PROD with code. You can see the main repository structure in the image below:

enter image description here

The protocol is that whenever we submit something to PRE-PROD, we e create a Change Folder, place it in the main repository, and also update the main folders, but sometimes we forget to do the second part. What i was trying to do in a automated way is: if there is a file with the same name in the main folder and the change folder they need the have the same modified date day (at least), this specific crossing i could easily do in Excel or even SQL. So, finally :P , what i needed help in, is getting into a csv fileformat (';' separating values, and '\n' separating rows), all the *.sql; *.xep; *.dll; *.aspx; *.gif from the main repository directory and sub-directories.

So far I i have tested with this dos commands:

dir *.sql *.xep *.aspx *.dll *.gif /s /a:-D>listWithDate.txt

this one gets me a list, ie: listWithDate.txt, that a i have formated in this fashion:

2012/03/19[2sapces]14:27[Nspaces]4.006[1space][filename]
2012/03/19[2sapces]14:27[Nspaces]10.006[1space][filename]

So needed help in on of the two:

batch to list Filenames and Date to a csv formated file

or

batch to format the listWithDate.txt into a csv formated file

Many thanks in advance ;)

4

2 回答 2

3

以下单行将输出文件时间戳(作为单个单位)、文件大小(以字节为单位)和文件名作为 CSV 行集:

>csvfile.txt (FOR %R IN (*.sql *.xep *.aspx *.dll *.gif) DO @ECHO "%~tR";%~zR;"%~nxR")

注意:这应该直接从命令提示符运行。如果您希望将其放入批处理脚本中,请将每个%字符加倍。

于 2012-05-18T18:36:14.377 回答
2

嗯,我认为这可能有效:

    @echo off
    echo.
    if exist newfile.csv del newfile.csv
    for /f "tokens=1-4* delims= " %%a in (listWithDate.txt) do (
        rem %%a is date %%b is time, %%c is filesize, %%d is filename
        rem use %%b or %%c as needed
        echo %%d, %%a >> newfile.csv
    )

这应该生成您正在寻找的文件,让我知道这是否适合您

于 2012-05-18T14:47:52.323 回答