powershell - How to create multiple subfolders? -
how create folder structure have 1 root folder, approximately 9 differently named subfolders; within these subfolders there set of differently named subfolders. have made 1 .csv file script. not feel writing out 30 lines of same code make these subfolders.
here have far:
$logsdir = "d:\logs" if (-not (test-path $logsdir)) { new-item -path $logsdir -itemtype directory | out-null } else { write-host "directory exists!" } $subfolders1 = import-csv "subfolders1.csv"; $subfolders1 | where-object {$_.type -eq 'subfolder'} | foreach-object { $subfolders1 = $_.name; new-item "$logsdir\$subfolders1" -itemtype directory } # ******sbf1 = first set of subfolders****** # ******sf-** = second set****** new-item -path "$logsdir\sbf1\sf-a1" -itemtype directory new-item -path "$logsdir\sbf1\sf-a2" -itemtype directory new-item -path "$logsdir\sbf1\sf-a3" -itemtype directory new-item -path "$logsdir\sbf2\sf-a1" -itemtype directory new-item -path "$logsdir\sbf2\sf-a2" -itemtype directory new-item -path "$logsdir\sbf2\sf-b2" -itemtype directory
i trying create log file folder tree. think got of down appreciated.
new-item
create missing parent folders, need list of leaf folders (with full path):
d:\logs\sbf1\sf-a1 d:\logs\sbf1\sf-a2 d:\logs\sbf1\sf-a3 d:\logs\sbf2\sf-a1 d:\logs\sbf2\sf-a2 d:\logs\sbf2\sf-b2
and create folders this:
get-content 'c:\path\to\subfolders.txt' | % { new-item -type directory -path $_ }
Comments
Post a Comment