Windows : How to list files recursively with size and last access date?

83,519

try this:

get-childitem D:\temp -rec | where {!$_.PSIsContainer} |
select-object FullName, LastWriteTime, Length | export-csv -notypeinformation -delimiter '|' -path file.csv
Share:
83,519

Related videos on Youtube

Baine Wedlock
Author by

Baine Wedlock

Updated on November 13, 2020

Comments

  • Baine Wedlock
    Baine Wedlock over 3 years

    I need a simple way to create a list of all files in a certain folder. (recursively)

    Each file must be in a single line. I also need the file size and the last access date in the same line, separated by a special character.

    The output (textfile) should look like this:

    c:\folder\file1.txt|400|2012-11-12 15:23:08
    c:\folder\file2.txt|200|2012-11-12 15:23:08
    c:\folder\file3.txt|100|2012-11-12 15:23:08
    c:\folder\sub folder\file4.txt|500|2012-11-12 15:23:08
    

    'Dir' seems not to be an option, because the German Special characters get messed up that way. (öäüß)

    Powershell handles the special characters well, but I couldn't make it so that the information for one file ends up in a single line:

    get-childitem D:\temp -rec | where {!$_.PSIsContainer} |  foreach-object -process {$_.FullName, $_.LastWriteTime, $_.Length}
    
  • Baine Wedlock
    Baine Wedlock over 11 years
    not bad, but it kills the german "Umlaute" : "D:\temp\????????????????\boink.txt"|"05.11.2012 15:31:28"|"0"
  • Baine Wedlock
    Baine Wedlock over 11 years
    i added -encoding default to the export-csv cmdlet and it works!
  • CB.
    CB. over 11 years
    @BaineWedlock Good! Forgot to mention -encoding parameter!
  • G. Lombard
    G. Lombard over 10 years
    A trivial point, but note that LastAccessTime isn't the same thing as LastWriteTime (since "last access date" was mentioned in the title).
  • CB.
    CB. over 10 years
    @G.Lombard Yes, but IIRC I copied what the user used in OP example. ;)