batch-filecmdwindowfile-listing

I need to list the path to all files in directory and sub directories and the creation date of the file in windows


I saw similar questions but nothing is working yet.

The end goal is to get a csv with col1 being file path and col2 being creation date.

Lets assume i have a directory C:/dir1, and inside it I have C:/dir1a and C:/dir1b and dir1a and dir1b both have files in them.

I can do

dir /s /b > dirfiles.csv

Which does give me all the file names, however when I do

dir /S /B /T:C > dirfiles_time.csv

nothing different happens.

How can i create a list of paths to every file (not directory just the files) and the creation time of that file?

Thanks

EDIT I do not care about the actual directory, only the path to the files themselves. Remove /b leaves a lot of information that i would need to remove

 Directory of D:\Dir1\dir1a

03/29/2018  11:20 AM    <DIR>          .
03/29/2018  11:20 AM    <DIR>          ..
03/29/2018  11:20 AM         5,583,992 16385  yadayada.tif
03/29/2018  11:20 AM         9,560,580 2278 yada.jpg
           2 File(s)     15,144,572 bytes

Solution

  • To fit in with your [batch-file] tag, just run this PowerShell command from the batch file.

    @Powershell -NoP -C "GCI $(GCI \"D:\Dir1\"|?{$_.PSIsContainer}|%%{$_.FullName}) -R|?{!$_.PSIsContainer}|Select FullName,CreationTime|Export-CSV -NoT \"dirfiles_time.csv\""
    

    You can change the initial directory, D:\Dir1, and csv output file, dirfiles_time.csv, just take care not to delete their opening and closing, \" sequence.

    If you want only the filenames without their paths then change Select FullName,CreationTime to Select Name,CreationTime. Likwise If you'd prefer the last modified times, change Select FullName,CreationTime to Select FullName,LastWriteTime.