Windows batch file to create csv list of file and dates

后端 未结 5 892
遥遥无期
遥遥无期 2021-01-15 13:39

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!).

Fields:

相关标签:
5条回答
  • 2021-01-15 13:54

    A one-line PowerShell command to write directory listing to CSV

    0 讨论(0)
  • 2021-01-15 14:01

    try this:

    @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
    
    0 讨论(0)
  • 2021-01-15 14:08

    I had a requirement to read the number of lines in two files and output to a csv file.

    @ECHO OFF
    cd "D:\CSVOutputPath\"
    echo Process started, please wait...
    echo FILENAME,FILECOUNT> SUMMARY.csv
    for /f %%C in ('Find /V /C "" ^< "D:\Trial\Salary.txt"') do set Count=%%C
    echo Salary,%Count%>> SUMMARY.csv
    for /f %%C in ('Find /V /C "" ^< "D:\Trial\Tax.txt"') do set Count=%%C
    echo Tax,%Count%>> SUMMARY.csv
    

    The > will overwrite the existing content of the file and the >> will append the new data to existing data

    0 讨论(0)
  • 2021-01-15 14:13

    Something like this might work:

    @echo off
    
    setlocal EnableDelayedExpansion
    
    (
      echo "Name","Modification Time","Creation Time"
      for %%f in (*) do (
        set "name=%%~nxf"
        if not "!name!"=="%~nx0" (
          set "mtime=%%~tf"
          for /f "tokens=1-3" %%d in (
            'dir /t:c "!name!" ^| find /i "!name!"'
          ) do set "ctime=%%~d %%~e %%~f"
          echo "!name!","!mtime!","!ctime!"
        )
      )
    ) > output.csv
    
    0 讨论(0)
  • 2021-01-15 14:17

    Here is a command line one liner that does not include the newly create list file in the list:

    (for /f "tokens=1-4*" %A in ('dir /a-d /tc^|findstr "^[0-9]"') do @if "%E" neq "FileList.csv" echo "%E",%A %B %C,%~tE)>"FileList.csv"
    

    Here is a batch script that does not include itself or the newly created list file:

    @echo off
    >"FileList.csv" (
      for /f "tokens=1-4*" %%A in (
        'dir /a-d /tc^|findstr "^[0-9]"'
      ) do if "%~f0" neq "%%~fE" if "%%E" neq "FileList.csv" echo "%%E",%%A %%B %%C,%%~tE
    )
    
    0 讨论(0)
提交回复
热议问题