-
os.path.exists to check if file or directory exists.
import os os.path.exists('/tmp/1.txt') os.path.exists('/tmp') -
os.path.isfile to check if file exists.
import os os.path.isfile('/tmp/1.txt')
import os
os.path.exists('/tmp/1.txt')
os.path.exists('/tmp')
import os
os.path.isfile('/tmp/1.txt')
def copy(if_path, of_path):
with open(if_path, 'rb') as in_file, open(of_path, 'wb') as out_file:
while True:
chunk = in_file.read(1024)
if chunk:
out_file.write(chunk)
out_file.flush()
else:
break