Windows batch file to create csv list of file and dates

后端 未结 5 896
遥遥无期
遥遥无期 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 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
    

提交回复
热议问题