Function to copy files from one folder to another

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
100 Answers 500 Comments 250 Likes First Anniversary
✭✭✭✭

How can we copy files from one directory to another?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    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