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
Solved

creating folders with subdirectories from a csv file.

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

829 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