Directory Listing includes Date Modified, File Size into text file/excel file

1

2

I want to list an entire drive's (Z:) directories, subdirectories, and files in a single text file with all the dates and the file sizes. I can then open the file inside Excel.

I am currently using the following command:

dir z:\ /s /o:gne >text.txt

Is there any way that I can get an output similar to what you usually get with the tree command, with all the files and subdirectories stacked in one and not listed separately?

What do I have to do or to input if I wanted to remove other unnecessary information like the time?

Kurisuchin

Posted 2015-01-27T01:39:39.947

Reputation: 13

Answers

5

powershell ls -r -fo Z:\ ^|?{!$_.PSIsContainer}^|Select DirectoryName,Name,BaseName,Extension,Length,CreationTime,LastAccessTime,LastWriteTime ^|epcsv Z:\excel.csv -En  UTF8 -NoType -Delim ';'
  • ^| - ^ - mask transporter/pipe symbol in cmd, | - pipe object
  • $_ - variable for the current object in the pipe line; sample:

    powershell 'a','B','c','d','F' ^|%{if($_.toLower() -gt 'b'){write $_}}
    
  • ? = where - check is not directory ?{!$_.PSIsContainer} cycle {}

  • ls -r - get all file in/and all subdirectory and current directory

  • -fo = -force - add to list hidden, system and read-only attribyte file
  • 'Z:\' - directory path, if use 'Z:' - set current directory at Z: cd.

  • select - select properties at ls pipe object

  • epcsv = Export-Csv - Export a PowerShell object to separated values (CSV) file.

  • -En = -Encoding - Encoding string The encoding for the exported CSV file. Valid values are: Unicode, UTF7, UTF8, ASCII, UTF32, BigEndian unicode, Default, and OEM. The default is ASCII.
  • -NoType = -NoTypeInformation - Omit the type information from the CSV file.
  • -Delim ';' - -Delimiter char A delimiter to separate the property values. The default is a comma (,). Enter a character, such as a colon (:). To specify a semicolon (;), enclose it in quotation marks.

result: enter image description here

STTR

Posted 2015-01-27T01:39:39.947

Reputation: 6 180

1Oh it worked. I have to check. – Kurisuchin – 2015-01-28T09:46:40.407

@CharisseDaitol Excellent! Can change the output by adding and removing properties in the select. – STTR – 2015-01-28T10:43:47.340

yep, I've tried it. Since I don't necessarily need to show every property.Thank you again. – Kurisuchin – 2015-01-29T01:18:21.940

1

The above has issues with spaces in directory names I found, this basic powershell command works better in my experience:

Get-ChildItem -r "Z:\" | select DirectoryName,Name,Extension,CreationTime,AccessTime,LastWriteTime | Export-Csv -Append -Path "Z:\export.csv" -En UTF8 -NoType -Delim ','

In addition using the Delimiter ";" is confusing to Excel and changing this to "," means excel can open the exported CSV without any further manipulation of the data.

wmcdade

Posted 2015-01-27T01:39:39.947

Reputation: 11