Share File Code by calling cmd in python-Python tutorial

Source: Internet
Author: User
Python3 calls cmd to copy the file, and passes the test in win7. For more information, see. The code is as follows:


Import OS

Def load ():
Filename = OS. getcwd () + r' \ fromto.txt'
If OS. path. isfile (filename ):
F = open (filename)
Try:
Lines = f. readlines ()
Finally:
F. close ()
Return lines
Else:
Print('create fromto.txt .')
Input ()
Exit ()

Def display (_ lines ):
Linenum = 1
S = 'Destination file \ n' of the serial number source file'
For line in _ lines:
S + = str (linenum) + ''+ line
Linenum + = 1
Return s + '\ n' + R' enter the serial number :'

Def work (s, _ lines ):
Cmd = r 'copy/y' + _ lines [int (s)-1]
Print (cmd)
OS. system (cmd)

If _ name _ = "_ main __":

Lines = load ()

While True:
Try:
S = input (display (lines). strip ()
If s. lower () = 'eg ':
Break
If int (s) = 0:
Lines = load ()
Print ('reloaded ')
Continue

Work (s, lines)

Except t:
Input ('-- Error --')



The fromto.txt format is the source file on the left of each line, and the target file (or target directory) on the right ).
In fact, it is packaged with copy.

Fromto.txt content

The code is as follows:


D: \ txt \ 1.txt d: \ txt \ 2.txt
D: \ txt \ *. txt d: \ txt2 \

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.