How to export folder length in characters using Powershell.

Welcome Forums General PowerShell Q&A How to export folder length in characters using Powershell.

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
4 months ago.

  • Author
    Posts
  • #108589

    Participant
    Points: 0
    Rank: Member

    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"
    
        }
    
    
  • #108593

    Participant
    Points: 92
    Rank: Member

    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
    
  • #108596

    Participant
    Points: 123
    Rank: Participant

    1 line

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

      Participant
      Points: 0
      Rank: Member

      thanks all!

The topic ‘How to export folder length in characters using Powershell.’ is closed to new replies.