python directory_Python askdirectory()

基于上次更新的文件移动。仅使用按钮3,我在目录末尾缺少斜线。这将导致路径与我要移动的文本文件合并:Exception in Tkinter callback

Traceback (most recent call last):

File "C:\Python34\lib\tkinter\__init__.py", line 1482, in __call__

return self.func(*args)

File "C:/Python34/check2.py", line 30, in fileMove

if os.stat(src).st_mtime > now - 1 * 86400:

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:/Somewhere/filenametextfile'

import shutil, sys, time, os

import tkinter as tk

from tkinter import *

import tkinter.filedialog

root = Tk()

def fileMove():

sourcePath = filedialog.askdirectory()

receivePath = filedialog.askdirectory()

source = sourcePath

dest = receivePath

files = os.listdir(source)

now = time.time()

for f in files:

src = (source) +f

dst = (dest) +f

if os.stat(src).st_mtime > now - 1 * 86400:

if os.path.isfile(src):

shutil.move(src, dst)

print("File move is Alright, Alright, Alright")

所有显示按钮def button_press():

if one:

x = 1

display.configure(text=x)

if two:

x = 2

display.configure(text=x)

if three:

x = 3

display.configure(text=x)

display = LabelFrame(root, bg="red", width="462", height="60")

display.pack()

one = Button(root, text="1", width="15", height="5",command=fromSource)

one.pack(side="left")

two = Button(root, text="2", width="15", height="5", command=toReceive)

two.pack(side="left")

three = Button(root, text="3", width="15", height="5",command=fileMove)

three.pack(side="left")

root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值