loop through subfolders

Viewed 27586

Hi I would like to create a batch file to get all the sub-folders.Can anyone please help me on this?

3 Answers

Here is a powershell script I use to get the size of the "School" folder within the Subfolder of each users' home folders. IE. N:\UserName\UserNameOSXProfile\School

SizeOfSchoolFolder.ps1

$schoolFolderTotalSize=0

$foundChildren = get-childitem *\*OSXProfile\School
foreach($file in $foundChildren){
    $schoolFolderTotalSize = $schoolFolderTotalSize + [long](ls -r $file.FullName | measure -s Length).Sum
}

switch($schoolFolderTotalSize) {
  {$_ -gt 1GB} {
    '{0:0.0} GiB' -f ($_/1GB)
    break
  }
  {$_ -gt 1MB} {
    '{0:0.0} MiB' -f ($_/1MB)
    break
  }
  {$_ -gt 1KB} {
    '{0:0.0} KiB' -f ($_/1KB)
    break
  }
  default { "$_ bytes" }
}

I pulled the adding numbers from: Adding up numbers in PowerShell

And the making folder size look pretty: Get Folder Size from Windows Command Line

And The \*\*OSXProfile\School as a search for a specific sub folder. Limit Get-ChildItem recursion depth

Related