SNyc-SFItem deleting empty folders

  • 1
  • Question
  • Updated 1 year ago
  • (Edited)
I am trying to set up a sync which will move all files, but leave the folders intact. I have the following command:

Sync-SfItem -ShareFilePath $DestPath -LocalPath $fullpath -Upload -Recursive -Overwrite -Move -KeepFolders #sync the folder

This syncs and moves the files, but the empty subfolders are deleted, and I need them to be left behind. How do I fix this? I thought the combination of "-Move -KeepFolders" was supposed to leave the folders alone, like it did in the CLI.

Here is the full script:
#set the paths here
$RootPath = "D:\Shares\Sharefile\test" #local root folder
$DestPath = "/test" #remote folder
#end paths

Add-PSSnapin ShareFile #load the plugin

$sfLogin = Get-SfClient –Name "D:\SharefileScripts\sflogin.sfps" #get the login credentials

New-PSDrive -Name sfdrive -PSProvider ShareFile -Root "/" -Client $sfLogin #open the connection

foreach($folder in get-childitem($RootPath)) #loop through the subfolders
    if ($folder.attributes -eq "Directory") #directories only
        Set-Location $folder.FullName #get the folder name
        $fullpath = $RootPath + "\" + $folder #+ "\*.*" #build the full path
        Sync-SfItem -ShareFilePath $DestPath -LocalPath $fullpath -Upload -Recursive -Overwrite -KeepFolders -Move #sync the folder

Remove-PSDrive sfdrive #close the connection
Photo of Jirvine


  • 12 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of Keith Lindsay

Keith Lindsay

  • 211 Posts
  • 40 Reply Likes
Hi Jirvine,  

I don't see anything wrong with your code so I've passed this to an engineer to look into. The PS SDK is a beta release and this seems like it could be a bug.  I'll update you as soon as I find out more.

Photo of Sebastiaan Thoen

Sebastiaan Thoen

  • 1 Post
  • 0 Reply Likes
Has this ever been fixed?  I am definitely seeing the same behavior- KeepFolders is not being respected.