I have the following tree structure of a folder called test.
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:UsersUSERDesktopest -Recurse | Select-Object directoryname, Name, LastWriteTime, CreationTime | Export-Csv -Path 'C:UsersUSERDesktopfiletxt.csv' -Encoding ascii -NoTypeInformation
What I achieved is the following :
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 PathFolder1 and etc... My expected result is the following :
Can someone please help me find a solution for the following problem ? Thank you
question from:
https://stackoverflow.com/questions/65947709/list-main-directory-and-its-sub-directories-using-directory-name-property-in-pow 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…