Hallo zusammen,
folgendes Problem, ich habe eine .csv Datei bekommen mit knapp 60k Einträgen. Die Struktur der csv soll in Ordnern nachgebildet werden und in den tiefsten Ordner jeweils nochmal 3 Ordner.
Also die csv sieht so aus:
test1;;;;;;;;;;
;2ordner ;;;;;;;;;
;o3;;;;;;;;;
;;;;;;;;;;
test 2;;;;;;;;;;
;abc1;;;;;;;;;
;abc2;;;;;;;;;
;abc3;;;;;;;;;
;;aa1;;;;;;;;
;;aa2;;;;;;;;
;abc4;;;;;;;;;
;abc5;;;;;;;;;
;;;;;;;;;;
gg1;;;;;;;;;;
;ggg1;;;;;;;;;
;;gggg1;;;;;;;;
;;;ggggg1;;;;;;;
Da sollte dann so aussehen:
test1\2ordner\A
test1\2ordner\B
test1\2ordner\C
test1\o3\A
test1\o3\B
test1\o3\C
test2\abc1\A
test2\abc1\B
test2\abc1\C
test2\abc2\A
test2\abc2\B
test2\abc2\C
test2\abc3\aa1\A
... usw.
Die Ordner Struktur geht allerdings zum Teil bis zu 10 Ordner tief.
Das was ich bis her habe funktioniert auch echt gut mit meiner kleinen Test Datei aber sobald ich die große 60k Zeilen Datei reinlade geht gar nichts mehr und er hängt alle Ordner aneinander:
test1\2ordner\o3\abc1\abc2\abc3\aa1\....
$CSVPATH = 'C:\test\text4.csv' $ROOTFOLDER = 'C:\test\test' $FIXEDFOLDERS = 'A','B','C' # --------------- $content = Get-Content $CSVPATH -ReadCount 1000 $level = 0 $currentpath = @() foreach($line in $content){ $cols = $line.replace('"','').split(';') if ($cols[0] -ne ""){ $first = $cols[0] }else{ 0..($cols.Count-1) | %{ if($cols[$_] -ne ""){ if($_ -gt $level){ $currentpath += $cols[$_] $level = $_ return }else{ $FIXEDFOLDERS | %{ md (Join-Path $ROOTFOLDER "$first\$($currentpath -join '\')\$_") -Force -Verbose } $currentpath = @($cols[$_]) $level = $_ } } } } } if ($level -gt 0){ $FIXEDFOLDERS | %{ md (Join-Path $ROOTFOLDER "$first\$($currentpath -join '\')\$_") -Force -Verbose } }