Find something on your HD

I was trying to search for something on a large file system, but between circular references in symbolic links creating errors with long paths etc it was harder than I thought it should be.

Here is some quick powershell to do a recursive, case insensative search while skipping symbolic links, but it does pick up hidden files and folders and ones with strange characters in the names.


function Recurse($path) {
# $path.tolower()
$global:counter++
$global:counter

$files = Get-ChildItem -literal $path -file -force
foreach ($file in $files) {
#$file.fullname.ToLower()
if ($file.fullname.ToLower().contains($searchstring)) {
# write-host $file.fullname -foregroundcolor "magenta"
$FoundArray.add( $file.fullname )
}
}
$folders = Get-ChildItem -literal $path -directory -force
foreach ($folder in $folders) {
# $folder.fullname
if ($folder.fullname.ToLower().contains($searchstring)) {
# write-host $folder.fullname -foregroundcolor "magenta"
$FoundArray.add( $folder.fullname )
}
if ( (get-item -literal $folder.fullname -force).Attributes.ToString().Contains("ReparsePoint") -eq $false) {
Recurse $folder.fullname
}
}
}
cls
$global:counter=0
$searchstring="dropbox"
$searchstring=$searchstring.tolower()
$FoundArray = New-Object System.Collections.ArrayList
recurse "C:\Users"
$FoundArray

Leave a Reply

Your email address will not be published. Required fields are marked *