循环遍历子文件夹

时间:2012-08-03 08:17:50

标签: powershell

您好我想创建一个批处理文件来获取所有子文件夹。任何人都可以帮我这个吗?

3 个答案:

答案 0 :(得分:11)

这在批处理文件或PowerShell中都是微不足道的:

批次:

for /r %%x in (*.sql) do (
    rem "(or whatever)"
    sqlcmd "%%x"
)

的PowerShell:

Get-ChildItem -Recurse -Filter *.sql |
    ForEach-Object {
        sqlcmd $_.FullName # or whatever
    }

答案 1 :(得分:1)

这是一个PowerShell脚本,用于获取" School"的大小。每个用户的子文件夹中的文件夹'家庭文件夹。 IE浏览器。 N:\用户名\ UserNameOSXProfile \学校

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" }
}

我从中添加了数字: Adding up numbers in PowerShell

制作文件夹大小看起来很漂亮: Get Folder Size from Windows Command Line

和\ * \ * OSXProfile \ School作为搜索特定子文件夹。 Limit Get-ChildItem recursion depth

答案 2 :(得分:0)

在所有文件名中用'abc'替换'xyz':

Get-ChildItem -Recurse -Filter *.mp3 | Rename-Item –NewName { $_.name –replace 'xyz','abc' }