Search Directories for file names with extensions longer than x

Welcome Forums General PowerShell Q&A Search Directories for file names with extensions longer than x

Viewing 3 reply threads
  • Author
    Posts
    • #28319
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      I'm trying to find a good way to search a directory and its sub folders for any files that have a file extension longer than x amount. I'm not finding any good answers on the best way to do this, any ideas?

      Thank You!

    • #28321
      Participant
      Topics: 1
      Replies: 44
      Points: 0
      Rank: Member

      Hey mate,

      Something like this should do the trick.

      Get-ChildItem C:\Folder -Recurse -File | Where-Object {$_.Extension.Length -gt 2}

      Change the int (2) to whatever you require.

    • #28327
      Participant
      Topics: 0
      Replies: 669
      Points: 0
      Rank: Member

      Only thing I'd suggest is making the comparison value a variable then your code is more versatile

      $test = 3
      Get-ChildItem C:\Folder -Recurse -File | Where-Object {$_.Extension.Length -ge $test}

      You might want to consider using -ge if you want to include that specific length

    • #28341
      Participant
      Topics: 21
      Replies: 51
      Points: 0
      Rank: Member

      I needed this as well, thanks for the assist!!

Viewing 3 reply threads
  • The topic ‘Search Directories for file names with extensions longer than x’ is closed to new replies.