# Mass Folder/File move

• Question
• Updated 2 years ago
We have a shard files folder that is becoming a monster.  It has about 1300 Folders and growing.

I was tasked with sorting these folders (clients) into smaller folders associated with the clients partner.

I have pulled a list from our database,
I was able, through powershell and the Sharefile API to locate each folder in the massive Shared folder to their corresponding partner.

Thing is, I can easily copy them over, but that does not retain the permissions.  I need to move them, and i swear, there is no easy way of doing this.

Keep in mind, I have limited knowledge with working on API's.  The more I read into it the more confusing it becomes.  I was never a CS student.

Any ideas on how i can accomplish this?
• 32 Posts

Posted 2 years ago

Andy Berryman, Software Engineer

• 27 Posts
Moving a folder from one location to another can be accomplished via a PATCH call to the Items endpoint.

Example:
• Assuming the desired Folder to move has ID = "fo111111-2222-3333-4444-555555555555"
• And the Destination Folder where you want to move it to has ID = "fo666666-7777-8888-9999-000000000000"
PATCH /sf/v3/Items(fo111111-2222-3333-4444-555555555555)

Body:

"Parent" : {
"Id" : "fo666666-7777-8888-9999-000000000000"
}
}

Hope that helps.

-Andy
(Edited)
• 32 Posts
Holy cow that worked

Andy Berryman, Software Engineer

• 27 Posts
Happy to help!  Also please be aware that the performance is dependent on the number of Child Items/Folders under the Folder that you are requesting to be moved.  So you may need to specify a longer timeout value if you know that you are attempting to move a large Folder.

- Andy
• 32 Posts
@Renato Dattilo Would you mind sharing the code? I have the same issue.

(Edited)
• 32 Posts
@Marcelo Rizzo

I am using powershell to accomplish this.  This is the code I am using to shift files over.

Add-PSSnapin ShareFile
$sfclient = Get-SfClient C:\path\to\sharefile.sfps New-PSDrive -Name SF -PSProvider ShareFile -Root / -Client$sfclient

#Find new folder ID#
##Let's say new folder is named ABC.  ABC is the initials of one of the partners in the firm.###

$Partner = ls "SF:\Shared Folder\" | ? {$_.filename -eq "ABC"}
$partnerID =$Partner.Id.ToString()
$fulllist = Send-SfRequest -Client$sfclient -Method GET -Entity items -Navigation Children -id [id of your source folder in sharefile]
$csv = Import-Csv -Path C:\path\to\file.csv ##Loop through the Shared Monster folder to match any folders that are close to the name of the client listed in the csv #### foreach ($client in $csv) { [array]$clients += $fulllist | Where-Object {$_.filename -like "$($client.client)"}

}

###Run me another loop.  This will take the original folder in the Monster folder and move (not copy) all files and folders WITH original permissions to the partner folder ####

foreach ($folder in$clients) {
$newfolder = '{ "Parent": {"Id":"'+$($partnerID)+'"} }' Send-SfRequest -Client$sfclient -Method PATCH -Entity Items -Id $folder.id.ToString() -Bodytext$newfolder
Start-Sleep -Seconds 30
}
##I put a start-sleep in between commands so in case there are many files to be moved over.  I could go deeper and have it check for the filecount and adjust accordingly, but I'm having this thing run late at night, so I don't care much about adjusting.  Management wants me to do this slowly over the course of 2 weeks.  Lucky me.###
(Edited)