Function to copy files from one folder to another

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 859
500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
✭✭✭✭

How can we copy files from one directory to another?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 859
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭
    Answer ✓

    The following can be used:

        import os
    
        def CopyFiles(dir1, dir2):
            '''
            Copy all files of dir1 directory into dir2 directory
            '''
            try:
                for filename in os.listdir(dir1):
                    shutil.copy(os.path.join(dir1,filename), dir2)
                return True
            except:
                ExtAPI.Log.WriteMessage("Error : Could not copy files")
                return None