简体   繁体   中英

Create a folder structure using PowerShell

I would like to create this folder structure using PowerShell:

D:\feb\win10\x64\Folder1
                 folder2

You are looking for the New-Item cmdlet.

Here an example to create a single folder using the New-Item cmdlet:

New-item "D:\feb#16\LV2\7212\win10\x64\audio" -ItemType Directory -force

Certainly you could do this for each the subfolders you want to create. You could also create a list of your subfolders using @('folder1' ,'folder2', ...) and iterate over these subfolders to create them. The following example uses the Join-Path cmdlet to combine the base path with the current sub folder which is $_ (the current pipeline object) and creates the directory using the above mentioned New-Item cmdlet:

@('audio', 'chipset', 'communication', 'docks', 'input', 'network', 'security', 'storage', 'video') |
    ForEach-Object {
        New-Item (Join-Path 'D:\feb#16\LV2\7212\win10\x64\' $_) -ItemType Directory -force
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM