Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Create parent and sub directories from file

$
0
0

Hi folks. I was wondering how to create a parent and sub directories from a list of text lines. I have the tried following formatting it into a CSV file, but it does has conflicts when the parent directory is already created after the first line. There is no guarantee that there will only be 1 or 2 sub directories, could be more. I guess once the first sub directory is created, i was hoping the PS script would not try to recreate it based on the sample data below. Sample data is accurately portraying what it will look like. Thanks a bunch.

 

$folders=import-csv c:\backup\sample.csv

foreach($folder in $folders){

  new-item ("c:\folder\"+$folder.Root+"\"+$folder.Sub1) -type directory

}

 

Sample data below :-

"c:\\stuff\\class\\school\\data",

"c:\\stuff\\class\\school\\data\\mike",

"c:\\stuff\\class\\school\\data\\samantha",

"c:\\stuff\\class\\school\\data\\samantha\\homework",

"c:\\stuff\\genius\\work",


Viewing all articles
Browse latest Browse all 6937

Trending Articles