finding all files with a certian length in a folder

I need to find all files 11 char in length and move them to a sub directory I cannot figure out how to do this ...here is what i have so far basically just listing all the files in a directory.

CLS
get-childitem "\\server\\Invoices\2016" -rec | where {!$_.PSIsContainer} | select-object name

August 25th, 2015 12:59pm

Is it just the name that is 11 characters or the name plus extension?

get-childitem "\\server\\Invoices\2016" -rec | where {!$_.PSIsContainer -and $_.Name.Length -eq 11} | select-object name
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 1:15pm

this is what i ended up doing

CLS
foreach($file in Get-ChildItem "\\server\Invoices\2016\" -Filter "*.pdf")
{
   $a = [string]$file
    if ($a.Length -lt 19 )
     {
      Move-Item "\\server\Invoices\2016\$a" "\\server\Invoices\2016\ScrewedUpFiles\"
      Write-Host Moving "\\server\Invoices\2016\$a" to "\\server\Invoices\2016\ScrewedUpFiles\$a"
     }
}     

  • Marked as answer by robMerritt 8 hours 39 minutes ago
August 25th, 2015 6:33pm

this is what i ended up doing

CLS
foreach($file in Get-ChildItem "\\server\Invoices\2016\" -Filter "*.pdf")
{
   $a = [string]$file
    if ($a.Length -lt 19 )
     {
      Move-Item "\\server\Invoices\2016\$a" "\\server\Invoices\2016\ScrewedUpFiles\"
      Write-Host Moving "\\server\Invoices\2016\$a" to "\\server\Invoices\2016\ScrewedUpFiles\$a"
     }
}     

  • Marked as answer by robMerritt Tuesday, August 25, 2015 10:31 PM
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 10:31pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics