我正在Ubuntu上用python编写一个程序来从远程Linux机器传输文件到My Host Ubuntu机器,这两台机器通过CAT5电缆直接相互连接。我的程序成功从其他Linux机器获取文件并显示传输的文件数。 但我想在远程linux机器上添加一个传输文件列表,其中包含传输文件的数量。
请帮助我改进编码以获得所需的结果。
import io,sys,os,subprocess
import Tkinter,ttk
from Tkinter import *
import tkMessageBox
def transFile():
num_files = len([f for f in os.listdir(path)if os.path.isfile(os.path.join(path, f))])
previous =num_files # Count Number of Files before Transferred New Files
ip ="192.168.2.34"
os.system("rsync -rav pi@"+ip+":python ~/") # Command To transfer Files
num_files = len([f for f in os.listdir(path)if os.path.isfile(os.path.join(path, f))])
present = num_files-previous
tkMessageBox.showinfo (" File Transfer", 'Number of Files Transfer is '+ str(present)+ '!')
def exitFiles():
root.quit()
root = Tk()
mainframe = ttk.Frame(root, padding="200 200 200 200")
mainframe.grid()
ttk.Button(mainframe, text="File Transfer", command=transFile).grid (column=10, row=3)
ttk.Button(mainframe, text="Exit", command=exitFiles).grid (column=95, row=3)
global process
path = os.path.expanduser("~/python") # Define path To play, delete, or rename video
root.mainloop()
答案 0 :(得分:1)
我添加了最后五行,它们会显示文件夹中的所有文件,可能是你会在解析后得到你需要的答案
def transFile():
num_files = len([f for f in os.listdir(path)if os.path.isfile(os.path.join(path, f))])
previous =num_files # Count Number of Files before Transferred New Files
ip ="192.168.2.34"
os.system("rsync -rav pi@"+ip+":python ~/") # Command To transfer Files
num_files = len([f for f in os.listdir(path)if os.path.isfile(os.path.join(path, f))])
present = num_files-previous
tkMessageBox.showinfo (" File Transfer", 'Number of Files Transfer is '+ str(present)+ '!')
a=0
for file in os.listdir('.'):
if fnmatch(file, '*.*'):
a +=1
ttk.Label(mainframe, text=file).grid(row=4+a, column=10)