Copy for file contents

os Import 
"" "
Requirements: implementation file copy the contents of
ideas:
source file: read out
the target file: Write to
" ""
DEF the FileCopy (by srcPath, desPath):
IF not os.path.exists (by srcPath): # determine whether there
print ( "Dude, {} file does not exist, do not copy the" .format (by srcPath))
return
iF not os.path.isfile (by srcPath): # whether the folder
print ( "{} is not a file, you can not copy." the format (by srcPath))
return
# punch source and destination files
srcFile = open (srcPath, "rb ") # punch content file read
desFile = open (desPath, "wb ") # open file writes to

size = os.path .getsize (srcPath) # acquisition source file size, in bytes


the while size> 0:

Content = srcFile.read (1024) # of bytes read 1024

desFile.write(content) #写入
size -= 1024

srcFile.close () # close the file
desFile.close ()
IF __name__ == "__main__": # execution program storage, put it plainly, run the program from here

fileCopy("a.txt","c.txt")

Guess you like

Origin www.cnblogs.com/nishoufeng/p/12063632.html