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?
Best Answer
^|
-^
- mask transporter/pipe symbol in cmd,|
- pipe object$_
- variable for the current object in the pipe line; sample:?
=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 atls
pipe objectepcsv
=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: