Author Posts

August 15, 2018 at 3:24 pm

Hi All,

i'm trying to export a list of folders in a directory, and then count the amount of characters that makes up the folder structure. I can't seem to get the export-csv to work.

I need to export a csv with the fullname which is the full path of the directory, and then next to it the length (character count). Any help is appreciated!

Get-ChildItem -Recurse -directory -Path "path of folder to start from" | Select-Object fullname | export-csv "export path"

$folders = Import-Csv "exported csv"

ForEach ($folder in $folders)
    {
   $folder, $folder.fullname.length | export-csv "result csv"

    }

August 15, 2018 at 4:01 pm

I think this is what you are looking for:

$folders = Get-ChildItem -Recurse -directory -Path "c:\powershell" | Select-Object fullname

$output = ForEach($folder in $folders)
{
    $folder | Select-Object -Property fullname, @{Name='Length';Expression={$_.fullname.length}}
}

$output | Export-Csv -Path .\result.csv -NoTypeInformation

August 15, 2018 at 4:11 pm

1 line


$(Get-ChildItem -Recurse -directory -Path "C:\temp" | Select Fullname , @{Name='Length';Expression={$_.fullname.length}} ) | export-csv "c:\temp\result csv"