Created
September 10, 2015 15:26
-
-
Save taisyo7333/3ec092bafd849643eedc to your computer and use it in GitHub Desktop.
Powershell Recursive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
.DESCRIPTION | |
.PARAMETER base_path | |
.PARAMETER max_depth | |
.PARAMETER depth | |
.EXAMPLE | |
Get-FolderHierarchy "C:\Windows" | |
.EXAMPLE | |
Get-FolderHierarchy "C:\Windows" 3 | |
.EXAMPLE | |
Get-FolderHierarchy "C:\Windows" 3 0 | |
.LINK | |
.NOTES | |
#> | |
param ( | |
[string]$base_folder_path, | |
[int]$max_depth=0, | |
[int]$depth = 0 | |
) | |
# 再帰的にフォルダ構成を調べて、フォルダ名をリストアップする。 | |
# フォルダ階層の深さに合わせてインデントする | |
function SearchFolders([string]$base_path,[int]$max_depth,[int]$depth) | |
{ | |
if( $max_depth -ne 0 ) | |
{ | |
if( $depth -ge $max_depth ) | |
{ | |
return; | |
} | |
} | |
$search = $base_path + "\*" | |
$folders = Get-ChildItem $search -Directory -Name | |
foreach ($folder in $folders ) | |
{ | |
$space = ' ' | |
$padding = $space.PadLeft( $depth * 4, ' ') | |
Write-Output "$padding + $folder" | |
$child_path = $base_path + "\" + $folder | |
SearchFolders $child_path $max_depth ($depth + 1) | |
} | |
} | |
SearchFolders $base_folder_path $max_depth $depth |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> .\Get-FolderHierarchy.ps1 "C:\users\ユーザー名\Music" 3 | |
+ iTunes | |
+ Album Artwork | |
+ Cache | |
+ Cloud Purchases | |
+ Download | |
+ iTunes Media | |
+ Downloads | |
+ iTunes に自動的に追加 | |
+ Music | |
+ Podcasts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment