Hi All,
I am trying to create a directory having folders and sub-folders from URL path. I could able to achieve it but there are issues if folder name is long.
Considering the below path
ABC/IT/DEF/LOGABLMESTRIC/Global Supply Chain/VOTC Weekly Reports - By Supplier, by region/WEEK24/DINGHUA-MEAD- WEEKLY VENDOR REPORT.XLS
By using PowerShell script, it could able to create folders till ' - By Supplier' and ignoring the remaining part till 'WEEK24'.
Please check the script below:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$Files = Import-Csv "C:\Microsoft PowerShell\GDWFilesTask\GDW Files task\LessFiles.txt"
$TargetPath = "E:\GDW Files"
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
ForEach ($File in $Files){
$FPath = $($File.Path)
$String = $FPath.ToString()
[System.Collections.ArrayList]$ArrayList = $String.split("/")
$ArrayList[0] = $TargetPath;
$ArrayList[2] = "ABC"
$ArrayList.RemoveAt(1)
$ArrayList = $ArrayList -notlike "*.*"
$b = ($ArrayList -join "\")
New-Item -ItemType directory -Path $b
$FileName = Split-Path $FPath -leaf
$output = $b +"\"+ $FileName
$wc.DownloadFile($FPath, $output)
write-host $FileName " is downloaded." -ForegroundColor Yellow
}
Is there any way, we can create complete directory with long folder and sub-folder names?
Please respond.
Thanks,
Kunal