How do I copy a file in Python?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
shutilhas many methods you can use. One of which is:srcto a file nameddst. Bothsrcanddstneed to be the entire filename of the files, including path.IOErrorexception will be raised.dstalready exists, it will be replaced.copy,srcanddstare path names given asstrs.Another
shutilmethod to look at isshutil.copy2(). It’s similar but preserves more metadata (e.g. time stamps).If you use
os.pathoperations, usecopyrather thancopyfile.copyfilewill only accept strings.