Johnrad
Johnrad

Reputation: 2655

Create folder directory from path?

I currently have a large list of folder paths that I want to use Powershell to create programatically. However my knowledge of Powershell, while growing, is still small.

E.G. - The given path is:

C:\Folder1\Folder2\Folder3\Folder4

I want to physically create this folder path using Powershell. Not all of the file paths have the same amount of levels.

I get the basic concepts of reading the contents of the text file and making a directory:

get-content c:\folderPaths.txt | Foreach-Object{
     MD newFolder
}

However I am not sure how I can parse the Folder path to get each level of the new directory.

Upvotes: 2

Views: 2403

Answers (1)

JPBlanc
JPBlanc

Reputation: 72610

Using the -force param, you can create all the folder in the tree in one action.

New-Item -ItemType directory C:\Folder1\Folder2\Folder3\Folder4 -Force

md is the alias to the function mkdir that call New-Item CmdLet.

Upvotes: 7

Related Questions