Python [Exercise] file operations: Copy files between directories

Source: Internet
Author: User


[Exercise] Specifies a source file that implements copy to the target directory.
Like copying/tmp/sample1.txt to/tmp/sample2.txt.
The original file needs to have Read permission (the default RT permission), the target file needs to write (w) permissions.

In [8]: With open ('/tmp/sample1.txt ', encoding= ' UTF-8 ') as F1:   ...:     with open ('/tmp/sample2.txt ', ' W ', encoding = ' Utf-8 ') as F2:   ...:         content = F1.read () ...   :         f2.write (content) ...   : in [9]: LS C:\python\171025 Catalogue 2017/10/26    <DIR> 2017/10/26-    <DIR>          . 2017/10/25  19:20            13,099 sample1.txt2017/10/26  09:01            13,099 sample2.txt

  

Only the file contents are copied, and the file meta information is not copied.

Python [Exercise] file operations: Copy files between directories

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.