Python calls CMD to copy file code sharing
- 2020-04-02 13:16:43
- OfStack
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(' Please create a fromto.txt.')
input()
exit()
def display(_lines) :
linenum = 1
s = ' The serial number The source file The target file n'
for line in _lines :
s += str(linenum) + ' ' + line
linenum += 1
return s + 'n' + r' Please 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() == 'exit' :
break
if int(s) == 0 :
lines = load()
print(' reloaded ')
continue
work(s, lines)
except :
input('--Error--')
The format of fromto.txt is that the left side of each line is the source file and the right side is the target file (or target directory).
Anyway is actually the packaging copy once.
Fromto. TXT content
d:txt1.txt d:txt2.txt
d:txt*.txt d:txt2