2021年1月28日星期四

List main directory and its sub-directories using directory name property in power shell

I have the following tree structure of a folder called test.

enter image description here

What I am trying to achieve is to list the main directory and its sub-directories under the column directory name using the Get-ChildItem property(Code is shown below).

Here's the code that I wrote in powershell :

Get-ChildItem -Path C:\Users\USER\Desktop\test -Recurse | Select-Object directoryname, Name, LastWriteTime, CreationTime | Export-Csv -Path 'C:\Users\USER\Desktop\filetxt.csv' -Encoding ascii -NoTypeInformation  

What I achieved is the following : enter image description here

As you can see, the directory name for Folder1 and Folder2 is missing and it should've been taken the same name of the path. Similarly for SubFolder1, the directory name should be Main Path\Folder1 and etc... My expected result is the following : enter image description here

Can someone please help me find a solution for the following problem ? Thank you

https://stackoverflow.com/questions/65947709/list-main-directory-and-its-sub-directories-using-directory-name-property-in-pow January 29, 2021 at 09:47AM

没有评论:

发表评论