dirTo = os.path.join(dirTo, leafDir) # create it inside dirTo try: os.mkdir(dirTo) dcount = dcount+1 except: print 'Error creating', dirTo, '--skipped' print sys.exc_type, sys.exc_value else: # copy all files, subdirs for file in os.listdir(dirFrom): pathFrom = os.path.join(dirFrom, file) if os.path.isdir(pathFrom): cpall(pathFrom, dirTo) # recur into subdirs else: # copy simple files try: pathTo = os.path.join(dirTo, file) if verbose > 1: print 'copying', pathFrom, 'to', pathTo bytesFrom = open(pathFrom, 'rb').read() open(pathTo, 'wb').write(bytesFrom) fcount = fcount+1 except: print 'Error copying', pathFrom, to, pathTo, '--skipped' print sys.exc_type, sys.exc_value if __name__ == '__main__': from cpall import getargs dirstuple = getargs() if dirstuple: apply(cpall, dirstuple) print 'Copied', fcount, 'files,', dcount, 'directories'
bytesFrom = open(pathFrom, 'rb').read() open(file, 'wb').write(bytesFrom) fcount = fcount + 1 except: print 'Error copying file', pathFrom, '--skipped' print sys.exc_type, sys.exc_value else: if verbose: print 'copying dir', pathFrom try: os.mkdir(file) except: print 'Error creating dir', dirTo, '--skipped' print sys.exc_type, sys.exc_value else: os.chdir(file) cpall(pathFrom) os.chdir(os.pardir) dcount = dcount + 1 if __name__ == '__main__': from cpall import getargs dirs = getargs() if dirs: dirFrom, dirTo = dirs if not os.path.isabs(dirFrom): dirFrom = os.path.join(os.getcwd(), dirFrom) os.chdir(dirTo) cpall(dirFrom) print 'Copied', fcount, 'files,', dcount, 'directories'
if verbose > 1: print 'copying file', pathFrom bytesFrom = open(pathFrom, 'rb').read() open(file, 'wb').write(bytesFrom) fcount = fcount+1 except: print 'Error copying file', pathFrom, '--skipped' print sys.exc_type, sys.exc_value else: if verbose: print 'copying dir', pathFrom try: os.mkdir(file) except: print 'Error creating dir', dirTo, '--skipped' print sys.exc_type, sys.exc_value else: os.chdir(file) cpall(pathFrom) os.chdir(os.pardir) dcount = dcount+1 if __name__ == '__main__': from cpall import getargs dirs = getargs() if dirs: dirFrom, dirTo = dirs if not os.path.isabs(dirFrom): dirFrom = os.path.join(os.getcwd(), dirFrom) os.chdir(dirTo) cpall(dirFrom) print 'Copied', fcount, 'files,', dcount, 'directories'
try: os.mkdir(dirTo) dcount = dcount + 1 except: print 'Error creating', dirTo, '--skipped' print sys.exc_type, sys.exc_value else: # copy all files, subdirs for file in os.listdir(dirFrom): pathFrom = os.path.join(dirFrom, file) if os.path.isdir(pathFrom): cpall(pathFrom, dirTo) # recur into subdirs else: # copy simple files try: pathTo = os.path.join(dirTo, file) if verbose > 1: print 'copying', pathFrom, 'to', pathTo bytesFrom = open(pathFrom, 'rb').read() open(pathTo, 'wb').write(bytesFrom) fcount = fcount + 1 except: print 'Error copying', pathFrom, to, pathTo, '--skipped' print sys.exc_type, sys.exc_value if __name__ == '__main__': from cpall import getargs dirstuple = getargs() if dirstuple: apply(cpall, dirstuple) print 'Copied', fcount, 'files,', dcount, 'directories'