Python 搜索超过20000个+;网络驱动程序中的文件。地球仪很慢。命令行给出错误消息

Python 搜索超过20000个+;网络驱动程序中的文件。地球仪很慢。命令行给出错误消息,python,python-2.7,search,Python,Python 2.7,Search,我需要从网络驱动程序中搜索一个文件(该文件夹包含两万个或更多文件) 我尝试使用glob进行搜索,但速度非常慢。通常需要50~60秒才能完成搜索 path = r'\\network\driver\' file = '12AC9K-XXE-849*' print(glob.glob(path+file)) 我还尝试使用命令行工具(所有系统都在Windows中): 我认为问题在网络中,因此我无法使用cmd.exe,因为我将收到错误消息: '\\network\driver\' CMD.EXE wa

我需要从网络驱动程序中搜索一个文件(该文件夹包含两万个或更多文件)

我尝试使用
glob
进行搜索,但速度非常慢。通常需要50~60秒才能完成搜索

path = r'\\network\driver\'
file = '12AC9K-XXE-849*'
print(glob.glob(path+file))
我还尝试使用命令行工具(所有系统都在Windows中):

我认为问题在网络中,因此我无法使用
cmd.exe
,因为我将收到错误消息:

'\\network\driver\'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
The system cannot find the path specified.
谢谢你,德莱尼

最后我找到答案并得到“dir”值

使用子流程

import subprocess

proc = subprocess.Popen(["dir/b", "\\network\driver\12AC9K-XXE-849*"], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
out = out.splitlines()
print out


谢谢大家的帮助

在命令行需要多长时间?命令行只需要1到2秒就可以找到文件。在第二种情况下,do
os.system(r“dir\\network\driver\12AC9K-XXE-849*”)
可以避免路径问题。我很好奇(而且没有ntfs共享的Windows机器)与glob相比如何
os.listdir(path)
。大约是同一时间吗?在命令行需要多长时间?在第二种情况下,命令行只需要1秒或2秒就可以找到文件do
os.system(r“dir\\network\driver\12AC9K-XXE-849*”)
来避免路径问题。我很好奇(并且缺少一台Windows机器和ntfs共享)与glob相比如何
os.listdir(path)
。差不多是同一时间吗?
import subprocess

proc = subprocess.Popen(["dir/b", "\\network\driver\12AC9K-XXE-849*"], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
out = out.splitlines()
print out