Solved

creating folders with subdirectories from a csv file.

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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.
Synchronize a new Active Directory domain with an existing Office 365 tenant
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

863 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

20 Experts available now in Live!

Get 1:1 Help Now