multi hierarchy folder create RRS feed

  • Question

  • Hi Scripting Guys!

      In some case i want Create multi hierarchy folder in a RootPath such as "E:\Test"

    And the  structure of multi hierarchy folder get from a Folder_structure.csv file with two attribute-row below

    [String]parent_directory and [String[]]Sub_directory

    parent_directory Sub_directory
    a                         "1","2","4","5"
    b                         "7","8","10","Tmp"
    c                         "3","6","Test"

    Finally i want to import Folder_structure.csv an in a loop create all the Sub_folders

    $RootPath = "E:\Test" #RootPath
    $Structure = Import-Csv 'E:\Folder_structure.csv' -Verbose 
    $Structure| % {
        $ChildItemPath = $RootPath + "\" + $_.parent_directory
        cd $ChildItemPath
        $_.Sub_directory | % {New-Item -ItemType Directory -Path . -name $_ -Verbose -Force -ea 0}
    the statement  "$_.Sub_directory | % {New-Item -ItemType Directory -Path . -name $_ -Verbose -Force -ea 0" in the loop
    I don't know how to make it work 

    Wednesday, July 1, 2020 5:48 PM

All replies

  • The file posted is not a CSV file.  You cannot have more commas than header fields.


    Wednesday, July 1, 2020 7:46 PM
  • parent_directory,Sub_directory

    I am so sorry that i just make it readable and don't paste the picture  like this 

    Thursday, July 2, 2020 1:49 AM
  • Wrong.


    Please take the time to look up and learn what a CSV file is.


    Thursday, July 2, 2020 2:10 AM
  • This just a example , because  some item in $_.Sub_director have space character
    And make sure everyone item in $_.Sub_director is a valid string  so i add double quotation marks
    Thursday, July 2, 2020 5:10 AM
  • Nothing you are saying makes any sense.  I suggest that you take some time to learn PowerShell before trying to continue.


    Thursday, July 2, 2020 6:39 AM
  • Okay  thanks for your suggestion
    Thursday, July 2, 2020 11:28 AM