Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:28:15+00:00 2026-06-18T10:28:15+00:00

I just created a little script that use a CSV file to batch create

  • 0

I just created a little script that use a CSV file to batch create folder. But I saw some people doing the folder creation using a different way.

CSV:

folder
4.1.1 Process
4.1.2 Score card
4.1.3 Strategy
4.1.4 Governance
4.1.5 Master plan  Calendar
4.1.6 Budget follow up
4.1.7 Budget documentation
4.1.8 Benchmarkvision
4.1.9 Std Documentation
4.1.10 Layout
4.1.11 Project
4.1.12 Training
4.1.13 Team structure
4.1.14 Work shop
4.1.15 Tools
4.1.16 Problem solving
4.1.17 Presentation
4.1.18 Working data zone
4.1.19 meeting
4.1.20 S
4.1.21 Miscellenous

Script:

#change the $folderlist path as it's a hard link.
$folderlist = Import-Csv "C:\folders.csv"
$rootpath = read-host "Enter the path of the root folder where the csv files will be created"

foreach ($folder in $folderlist){
    $path = $rootpath+$folder.folder
    new-item -type directory -path $path
    } 

Quite simple, but I saw people use things like $(_$.folder) or other functions that I don’t understand. Is there someone that can show me an other way to do it using $_ and %{ }?

I hope my question is clear if not I will give more information.

John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:28:16+00:00Added an answer on June 18, 2026 at 10:28 am

    The only thing I think I would change (assuming that your input CSV is properly formatted) is how you’re constructing your path.

    foreach ($folder in $folderlist){
        $path = join-path -path $rootpath -childpath $folder.folder;
        new-item -type directory -path $path;
        } 
    

    Alternate:

    foreach ($folder in $folderlist){
        new-item -type directory -path $rootpath -name $folder.folder;
        }
    

    Alternate 2 (derived from above):

    $folderlist|foreach-object {new-item -type directory -path $rootpath -name $_.folder;}
    

    Alternate 3 (derived from above):

    $folderlist|foreach-object {new-item -type directory -path (join-path -path $rootpath -childpath $_.folder);}
    

    % is an alias for foreach-object – I always use the expanded alias in scripts & explanations like this, to ensure that everything is crystal clear.

    Edit: One more way that’s even more concise and depending on the size of your CSV file, could be better on memory usage.

    $rootpath = read-host "Enter the path of the root folder where the csv files will be created"
    Import-Csv "C:\folders.csv"|foreach-object {new-item -type directory -path (join-path -path $rootpath -childpath $_.folder);}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just created a .dll file that has some methods. And I have a another
I've just created a little app that programmatically compiles code using the C# Compiler,
Just created a WSS site with a some custom web-parts. But I get an
I was trying to create a quick little script that would insert data into
I've created a simple class and got a little problem: I just want to
I am trying to create a little ajax chat system (just for the heck
I need to create some way to get a local WAR file deployed on
I've created a Web Service that I need to use in my .ascx page.
I've recently wrote a little script that get's my Twitter feed and caches it
I am trying to create a script to batch mark a group of users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.