创建递归目录结构

时间:2017-11-30 18:22:09

标签: powershell

我想要一个powershell脚本来创建如下所示的目录结构,但是通过字母数字范围。我希望能够指定它应该有多少目录。

0
-00
--000
--001
--002
-01
--010
--011

这是我到目前为止所拥有的。我对任何有关完成任务的更好方法的建议持开放态度。

## Create File structure
param([string]$RootPath = "",[int]$DirsDeep = "")

$RootPath = "C:\Temp\Catalog\"
$DirsDeep = 2


##Initializes Alpha Array
$AlphaNumericArray = @("0\","1\","2\","3\","4\","5\","6\","7\","8\","9\","A\","B\","C\","D\","E\","F\","G\","H\","I\","J\","K\","L\","M\","N\","O\","P\","Q\","R\","S\","T\","U\","V\","W\","X\","Y\","Z\")

##Function creates dirs in $CreationPath
function CreateDirs ($CreationPath) {
    foreach($Dir in $AlphaNumericArray){
        New-Item -Path $CreationPath -Name $Dir -ItemType "directory"

        }
}   
#Function to get Dir Children
function GetDirChildren ($ChildPath) {
    $DirChildren = Get-ChildItem -Path $ChildPath -Directory -Recurse
}


CreateDirs $RootPath
Write-Host $RootPath


for ($Count=0; $Count -lt $DirsDeep; $Count++){
    foreach($ChildDir in (Get-ChildItem -Path $RootPath -Directory -Recurse)){
        Write-Host $ChildDir
        Pause
        CreateDirs $ChildDir
    }
}

0 个答案:

没有答案