Pnp-powershell: Copy-PnpFile cant copy empty folders

Created on 7 Aug 2019  路  13Comments  路  Source: pnp/PnP-PowerShell

Reporting an Issue or Missing Feature

When using v3.12.1908.1 (2019-Aug) the copy file issue reported in #2103 seems to be resolved. But when copying empty folders (from one site collection to another) you get a new error.

Expected behavior

Copying folders (including empty folders) should be OK - no change in documentation for the cmdlets

NOTE! This is working using v3.10.1906.0 (2019-June) - but then the file error, reported in #2103 is kicking in.

Actual behavior

Command throws the following error:
Copy-PnPFile : The directory is not a subdirectory of the root directory

Steps to reproduce behavior

  1. Create an empty folder with empty sub-folders ($CopySourceUrl)
  2. Copy that folder to another site collection/document lib ($TargetRelativeUrl)

Connect-PnPOnline -Url $Url -AppId $AppId -AppSecret $AppSecret
Copy-PnPFile -SourceUrl $CopySourceUrl -TargetUrl $TargetRelativeUrl -SkipSourceFolderName -OverwriteIfAlreadyExists -Force

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [x ] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

3.12.1908.1

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means
Needs

All 13 comments

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

I'm on it. There were no unit tests for this scenario. Will add them and do some code corrections, if needed.

I鈥檒l do some more (unit) testing on this issue tomorrow.
I did put a fix together, but it feels like previous versions were not able to fulfil this requirement. Either there was a change in PnP sites core or I鈥檓 not seeing the difference between the latest and previous versions. Hope to figure it out soon.

I did a quick test with the July release. Worked fine for me:

Import-Module SharePointPnPPowerShellOnline -RequiredVersion 3.11.1907.0
Connect-PnPOnline https://<Tenant>.sharepoint.com/
Copy-PnPFile -SourceUrl "Shared%20Documents/EmptyFolder" -TargetUrl "Shared%20Documents/Target" -Force

With the August release it worked to, but you need to keep the %20 encoding.

Import-Module SharePointPnPPowerShellOnline -RequiredVersion 3.12.1908.1
Connect-PnPOnline https://<Tenant>.sharepoint.com/
Copy-PnPFile -SourceUrl "Shared%20Documents/EmptyFolder" -TargetUrl "Shared%20Documents/Target" -Force

What bothers me, is that I was not able to get this to work by running a unit-test in the first place.

What I did so far:
I did change the code to properly use ResourcePath at anz point of the code and to create the target path. Will do some more testing on this, to be sure to not break anything else.

@frisla Could you confirm, that the cdmlet works for you by only having on empty folder and copying this folder to another folder with the command above?

I have a follow up on Copy-PnPFile. I can copy a folder into a different folder in the same document library, but I can't copy a folder from one document library to a different document library. I get the error, "The directory is not a subdirectory of the root directory."

@ajhosek i will have a look into this scenario. Thank you for the feedback!

@andikrueger I can copy an empty folder between document libraries in the same site. When I try to copy a folder - both empty and containing files - to a document library in a subsite of the same tenant, I receive the error: "The directory is not a subdirectory of the root directory."

@andikrueger Do you have any updates on this issue? Thanks

I did push my latest changes to this branch: https://github.com/andikrueger/PnP-PowerShell/tree/issue-2195-empty-folder

I did not have the time to add some more unit tests for the scenarios above. Hope I get it done by mid next week.

Do you know when your fix will be released? I just updated to 3.13.1909.0 released 9/9/2019 and I'm still getting the same error:
The directory is not a subdirectory of the root directory
This occurs when copying a folder with subfolders and files across site collections.

Negativ. I think the fix did not make it to the September release.

Repeating request.
Do you know when your fix will be released? I just updated to 3.14.1910.0 released 10/7/2019 and I'm still getting the same error:
The directory is not a subdirectory of the root directory
This occurs when copying a folder with subfolders and files across site collections.

@anthonyrubalcaba Hopefully with the next release. The PR got merged.

Was this page helpful?
0 / 5 - 0 ratings