Solved

creating folders with subdirectories from a csv file.

Posted on 2013-11-11
1
936 Views
Last Modified: 2014-09-12
I have a spreadsheet with about 500 rows.  I would like a directory to be a created from each row.  Under each directory, I would like the same 5 subfolders to be created.  An example of the first couple rows of the spreadsheet would be:

dir1, sub1, sub2, sub3, sub4
dir2, sub1, sub2, sub3, sub4
dir3, sub1, sub2, sub3, sub4

Is there a batch file or script to automate this task?

Thanks!
0
Comment
Question by:akyuen
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39640203
Hi,

this will read a CSV assuming there is a header line where the initial directory column is named "Directory"  (the dir1,.. in your sample), checks if the folder does not exist and then creates five subdirectories:

$importFile = "F:\EE\EETestDirectory.csv"
$csvContent = Import-Csv $importFile
$baseDirectory = "F:\EE\TestOut\"
foreach($line in $csvContent) {
    $currentFolder = $baseDirectory + $line.Directory
    if (!(Test-Path $currentFolder)) {
        New-Item $currentFolder -type directory
        for ($i = 1;$i -le 5;$i++) {
            New-Item "$currentFolder\sub$i" -type directory
        }
    }
}
Write-Host "Done"

Open in new window


Attached sample CSV as well.

HTH
Rainer
EETestDirectory.csv
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now