Shuhaib K V
Shuhaib K V

Reputation: 51

Create a folder structure using PowerShell

I would like to create this folder structure using PowerShell:

D:\feb\win10\x64\Folder1
                 folder2

Upvotes: 5

Views: 7115

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

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
    }

Upvotes: 5

Related Questions