HOME | Blog | YouTube | LinkedIn | About Me         || Calculators    | SoftEng/Tech Posts    | Code/Scripts

Python - Copy all files from Directory A to Directory B



#!/usr/bin/python
import os
import shutil

############################################################
def main():
    isGood = copyFiles("C:/temp/test1", "C:/temp/test2")
    if isGood:
        print "*** copyFiles successful"
    else:
        print "*** copyFiles FAILED"
############################################################

def copyFiles(srcDir, destDir):
    isSuccess = True    try:
        src_files = os.listdir(srcDir)
        for file_name in src_files:
            full_file_name = os.path.join(srcDir, file_name)
            if os.path.isfile(full_file_name):
                shutil.copy(full_file_name, destDir)

        isSuccess = True

    except:
        print ":::ERROR: Failed to copy from: " + srcDir + " to: " + destDir
        isSuccess = False
    return isSuccess

############################################################

if __name__ == "__main__": main()


almirsCorner.com

#python #programming #code #coding #software #softwaredeveloper #softwareengineering #programmer

No comments:

Post a Comment