Hi, I have a script that downloads files from SP library (code below), and I would need to extract folder name of the item.
The source SP library has many folders and I'd need to capture the folder name for each downloaded item and add it to the target path or target file name. how could this be approached?
#Extract the each list item from the List Items collection.
ForEach($Item in $ListItems)
{
try
{
$Ctx.Load($Item.File)
$Ctx.ExecuteQuery()
$SourceFile=$Item.File.ServerRelativeUrl;
$TargetFile=$TargetFolder + "\" + $Item.File.Name;
If ($Action -ne "UpdateOnly")
{
FileDownLoadFromSPOnlineLibrary -SPOSiteURL $SiteURL -SourceFilePath $SourceFile -TargetFilePath $TargetFile
$fileDownloadingMessage="Downloaded: "+$Item.File.Name;
Write-Log $fileDownloadingMessage
}