Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

creating folders with subdirectories from a csv file.

Posted on 2013-11-11
1
Medium Priority
?
1,232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

604 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