Welcome to the new Box Support website. Check out all the details here on what’s changed.

Recursive file Copy - Python Box SDK

Answered
New post

Comments

4 comments

  • mwiller

     As documented, the Folder Copy API is already recursive and will copy over the contents of the folder for you — is there a specific reason for wanting to copy files and subfolders individually?

    0
    Comment actions Permalink
  • shynee

    Thank you Willer. Totally Overlooked Copy Folder API(client.folders.copy(folderID, destinationFolderID)). I wanted to copy one by one and check SHA1 for file integrity.  But that could be a separate function. Appreciated.

    0
    Comment actions Permalink
  • shynee

    We have large Isilon Shares with millions of files. We are trying to move some of the files which were accessed in the last one year. That was the main reason for copying file by file. I did a test copy against around 250 files (total 18MB)  and it took 15 minutes. if I copy file be file, it will take months. Copying folders seems the way to go. Then apply expiration policy to take care of the files which are not accessed in a long time.

    0
    Comment actions Permalink
  • Mxolisi

    Hi  and , I don't know if this is possible but I want to copy files from a shared folder to a folder on my own account using a python script.

    Right now I can only get the metadata of the files and folders shared but I can't download them so I thought maybe I should go the copy route.

    Here is the function I'm using:

    def download_from_link(self, links😞
    extensions = ['jpg', 'jpeg', 'png']
    try:
         for link in links:
              _shared_folder = self.client.get_shared_item(link)
              print(_shared_folder.type)
               if _shared_folder.type == 'file':
                     # downloading file
               elif _shared_folder.type == 'folder':
                      self.client.folders.copy(_shared_folder.id,destination_id)
                      for _file in _shared_folder.get_items(limit=1000😞
     
                            if "Original Files" in _file.name:
                                  for _file_ in _file.get_items(limit=1000😞
                                        ext = _file_.name.split('.')
                                        if ext[-1] in extensions:
     
                                        print(_file_.name)
                                        output_file = open(_file_.name, 'wb')
                                        print(output_file)
                                        download_file = self.client.file(_file_.id).get()
                                        self.client.file(_file_.id)
                                        download_file.download_to(output_file)
     
    I'm sorry about the Indentation I had to do it manually since I the text editor can't format a python script.
    0
    Comment actions Permalink

Please sign in to leave a comment.