Hello!
I have a script.
Add-PSSnapin microsoft.sharepoint.powershell
$libraryname = "mydoc"
$csvpath = "c:\Temp\test.csv"
# Import CSV
[array]$FolderList = Import-Csv $CSVPath
# Script Variables
$spWeb = Get-Spweb http://sptesztlk
$spList = $spWeb.Lists[$LibraryName]
Foreach ($folderGroup in $FolderList)
{
# Create Parent Folder
$parentFolder = $spList.Folders.Add("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$folderGroup.Root)
$parentFolder.Update()
Write-Host "The Parent folder" $folderGroup.Root "was successfully created" -foregroundcolor Green
# Loop variables
$i = 1
$col = "S"
$colID = $col + $i
While ($folderGroup.$colID -ne $null)
{
$newSubfolder = $splist.Folders.Add($parentFolder.Folder.ServerRelativeUrl, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$folderGroup.$colID)
$newSubfolder.Update()
Write-Host "The subfolder" $folderGroup.$ColID "was successfully created" -foregroundcolor Cyan
$i++
$colID = $col + $i
$a = 1
$asd = "D"
$asdID = $asd + $a
while ($folderGroup.asdID -ne $null)
{
$newSSubfolder = $splist.Folders.Add($newSubFolder.Folder.ServerRelativeUrl, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$folderGroup.$asdID)
$newSSubfolder.Update()
Write-Host "The subfolder" $folderGroup.$asdID "was successfully created" -foregroundcolor Blue
$a++
$asdID = $asd + $a
}
}
}
$spWeb.Dispose()
I have a problem with the sub-subfolder creation. How can i tell the program to create a 2nd level subfolder in which subfolder?
csv file contain:
Root,S1,S2,S3
Parent1,Sub1,
Parent2,Sub1,Sub2
Creating the parent and the subfolder is ok. But i don't know to go deeper.
Or what if i don't know how many level i need for the tree creation.
I Hate Mondays