![](/img/trans.png)
[英]Running Python Code in VS Code and Cannot Find Files in Same Folder
[英]python ShellExecute cannot find files on a shared folder on another computer
最近我使用模塊win32print和win32api完成python批量打印PDF文件。 當我在本地計算機上的 select pdf 文件時,它做得很好。 但是,當我將 select pdf 文件放在另一台計算機上的共享文件夾(文件夾路徑如“\\filepath”)上時,出現了問題,顯示“pywintypes.error: (2, 'ShellExecute', '系統找不到文件指定)”。 我不知道為什么。
# Batch print pdf files
import win32print
import win32api
import os
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
def print_file(filename):
open(filename,"r")
win32api.ShellExecute(
0,
"print",
filename,
'/d:"%s"' % win32print.GetDefaultPrinter(),
".",
0
)
root = tk.Tk()
root.withdraw()
files_path = filedialog.askopenfilenames()
num = len(files_path)
if num == 0:
messagebox.showinfo("Prompting","No files selected!")
else:
msg = messagebox.askyesno('Prompting', 'Pring'+ str(num)+"files?")
if msg:
i = 0
for file_path in files_path:
if file_path.endswith("pdf"):
print_file(file_path)
i = i + 1
messagebox.showinfo("Prompting","Done!\n" + "Totally printing"+str(i)+"files!")
else:
messagebox.showinfo("Prompting","Nothing done!")
也許你可以使用這些:
import glob
path = r'./folder/folder/'
all_files = glob.glob(path + "/*.pdf")
files = all_files[:-1]
print("number of pdf files: ", len(files))
for filename in files:
//open file
在另一台計算機上(文件夾路徑如“\\filepath”),出現問題,顯示“pywintypes。錯誤:(2,'ShellExecute','系統找不到指定的文件)”。 我不知道為什么。
答案與上面在您添加一個額外的問題中發布的相同,您需要使用"\\\\server\\filepath"
,使用 \ 被認為是一種轉義,因此每個都需要加倍。 局域網文件共享是\\served/path/filename
除非它映射到驅動器letter:/path/filename
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.