我喜欢rsync
命令,但想在上面放一个GUI来帮助我学习python。一切正常,只是我不知道如何获得rsync
命令和用户提供的命令行输入。
OSX 10.15.7 Sublime(4107版(
import PySimpleGUI as sg
import os
from pathlib import Path
import subprocess
layout = [[sg.Text('Sync Your Files')],
[sg.Text('Source Folder', size=(15, 1))],
[sg.FolderBrowse(key='source'), sg.InputText(key='-source-')],
[sg.Text('Target Folder', size=(15, 1))],
[sg.FolderBrowse(key='target'), sg.InputText(key='-target-')],
[sg.Button('Submit'), sg.Button('Cancel')]],
window = sg.Window('Simple Data Entry Window', layout)
event, values = window.read(close=True)
print(values['-source-'])
print(values['-target-'])
begining = (values['-source-'])
end = (values['-target-'])
syncommand = ("rsync -avzh ")
args=[syncommand + begining + end]
print(args)
if event == 'Submit':
os.system('args')
execute(args)
print('Your files from ', values['-source-'], 'were copied to your ',
values['-target-'])
else:
print('User cancelled')
更改为:
args=[syncommand , begining+'/*' , end]
print(args)
if event == 'Submit':
os.system(' '.join(args))
并移除";execute((">存储在列表中的第一个需要放入","而不是"+",因为使用"+"的结果是";开始/路径/结束/路径";而不是";开始/路径/"结束/路径/">第二个需要在开头添加'/*',否则将复制文件而不是文件的内容第三个添加"。join他将列表转换为字符串以使os.system
正常工作。