Download Folder Contents But Not the Folder Itself

  • 1
  • Question
  • Updated 1 week ago
I've hit another snag on my file transfer PowerShell script.

I need to DOWNLOAD the files within a ShareFile folder to a folder of the same name on our server.  Problem the command is creating another subfolder of the same name within the folder on the server, so it's ending up as *\Directory\Folder\Folder.  I don't want the "Folder" subfolder.

I've seen many discussions of using the asterisk wildcard on local drive locations, when UPLOADING files to ShareFile.  But it doesn't seem to work for DOWNLOADING.

I'm using: Sync-SfItem -ShareFilePath "/ProjectPath/Folder" -Synchronize -Download -LocalPath "D:\Shares\Projects\Project Path\Folder" -Overwrite

which results in D:\Shares\Projects\Project Path\Folder\Folder.  I only want the files inside "folder", not the entire folder itself.

Photo of patrick94gsr

patrick94gsr

  • 7 Posts
  • 1 Reply Like

Posted 1 year ago

  • 1
Photo of Tyler Napier

Tyler Napier

  • 3 Posts
  • 1 Reply Like
Move the local path back one. -Overwrite makes sure you can still write to it. 
Sync-SfItem -ShareFilePath "/ProjectPath/Folder" -Synchronize -Download -LocalPath "D:\Shares\Projects\Project Path" -Overwrite
(Edited)
Photo of patrick94gsr

patrick94gsr

  • 7 Posts
  • 1 Reply Like
Thanks, I actually forgot about this, but it's still an issue.

So is there no way to have it copy only the files within a folder and not the folder itself?  In some cases I might have some files in that target folder on the local drive, but with the above syntax, the whole folder gets overwritten with whatever is on ShareFile.
Photo of Tyler Napier

Tyler Napier

  • 3 Posts
  • 1 Reply Like
What you described is what would happen if you used some combination of the -Synchronize and -Strict switches.

It doesn't overwrite the whole folder. The -Overwrite switch only overwrites items that it matches with. It's like in Windows when you combine two folders of the same name--only files with the same names are overwritten.

I ran some tests today.
I had a folder in \\localpath\Testing called Test (i.e., \\localpath\Testing\Test) with contents in it. 
Command: Sync-SfItem -ShareFilePath /Testing -Download -LocalPath \\localpath\ -Overwrite
This copied the contents of /Testing to \\localpath\Testing and kept my \\localpath\Testing\Test folder with all its contents. 

Try it out. 
There would be an issue of course if you had a subfolder in the Sharefile path with the same name as a subfolder in the local path and you didn't want them to sync. I haven't been able to get the Powershell commands to only copy files and NOT folders from a path. Powershell sees files and folders as the same thing. 

Photo of patrick94gsr

patrick94gsr

  • 7 Posts
  • 1 Reply Like
Thanks, yeah I tried it and it does seem to copy just the files as you described.  Thanks for the tips!