Solved

creating folders with subdirectories from a csv file.

Posted on 2013-11-11
1
1,101 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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). …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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