Locating all subdirectories matching a string or partial string
Try something like this:
$BaseDir = "C:\Dir1"$NameToFind = "\DirA"$MyVariable = Get-ChildItem $BaseDir -Recurse | Where-Object { $_.PSIsContainer -and $_.Name.EndsWith($NameToFind)}
This should go through all the directories in the tree, starting at C:\Dir1 and return the directory object DirA back to you.
If you only need the path of the directory, just use:
$MyVariable.FullName
You don't need to post process this with Where-Object
. -Filter
can already get this for you. If you have at least PowerShell 3.0 then you can remove Where-object
in its entirety.
(Get-ChildItem -Path D:\Data\Dir1 -Filter "*DirA*" -Recurse -Directory).Fullname
That will return all directories under the Path that have the exact name of DirA. If you need partial matches then just use simple wildcards: -Filter "Dir*some"
If running PowerShell 2.0 then you can do the following.
Get-ChildItem -Path D:\Data\Dir1 -Filter "*DirA*" -Recurse | Where-Object {$_.PSIsContainer} | Select-Object -ExpandProperty Fullname
Hi find the below script it should work correct me in case if it's wrong,
$rootFolder = "D:\Data" ##Mention the root folder name here###$folderItems = (Get-ChildItem $rootFolder) $subfolderslist = (Get-ChildItem $rootFolder -recurse | Where-Object {$_.PSIsContainer -eq $True -and $_.Name -like "*2018-08*"} | Sort-Object)foreach ($curfolder in $subfolderslist){ #Write-Host 'Folder Name '$curfolder yyyy-mm-dd $subFolderItems = (Get-ChildItem $curfolder.FullName) foreach($item in $subFolderItems) { $currentfile=$rootFolder+"\"+$curfolder+"\"+$item #Write-Host 'file path '$mfilepath Write-Host " " if ((Get-Item $currentfile ).length -gt 3mb) { Write-Host "File size greater than 3 MB hence "$true } else { Write-Host "File size less than 3 MB hence "$false } } }