[英]python ShellExecute cannot find files on a shared folder on another computer
Recently I use modules win32print and win32api to accomplish batch printing PDF files by python.最近我使用模块win32print和win32api完成python批量打印PDF文件。 When I select pdf files on my local computer, it did well.
当我在本地计算机上的 select pdf 文件时,它做得很好。 However, when I select pdf files on a shared folder on another computer(the folder path like "\\filepath"), The problem appeared, which showed "pywintypes. error: (2, 'ShellExecute', 'The system cannot find the file specified)".
但是,当我将 select pdf 文件放在另一台计算机上的共享文件夹(文件夹路径如“\\filepath”)上时,出现了问题,显示“pywintypes.error: (2, 'ShellExecute', '系统找不到文件指定)”。 I do not know why.
我不知道为什么。
# 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!")
probably you can use these:也许你可以使用这些:
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
on another computer(the folder path like "\\filepath"), The problem appeared, which showed "pywintypes. error: (2, 'ShellExecute', 'The system cannot find the file specified)".
在另一台计算机上(文件夹路径如“\\filepath”),出现问题,显示“pywintypes。错误:(2,'ShellExecute','系统找不到指定的文件)”。 I do not know why.
我不知道为什么。
The answer is that same as posted above in your question where you added one extra, you need to use "\\\\server\\filepath"
using \ is considered an escape so each needs to be doubled.答案与上面在您添加一个额外的问题中发布的相同,您需要使用
"\\\\server\\filepath"
,使用 \ 被认为是一种转义,因此每个都需要加倍。 A lan file share is \\served/path/filename
unless its mapped to a drive letter:/path/filename
局域网文件共享是
\\served/path/filename
除非它映射到驱动器letter:/path/filename
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.