[英]how to get the string of the *xlsx file path name in Python?
there are several different format files in the Documents 文档中有几个不同的格式文件
I need to get a string which is the *xlsx format files path I using below code ,but it return a error as like below 我需要使用下面的代码获取一个字符串,该字符串是我使用的* xlsx格式的文件路径,但是它返回如下错误
PATH= u'F:\Workfiles\周报\\forupdate'
filepath = os.path.join(PATH,str(os.listdir(PATH)))
IOError: [Errno 2] No such file or directory: u"F:\\Workfiles\\\周\报\\forupdate\\[u'suxl20170821.xlsx']" IOError:[Errno 2]没有这样的文件或目录:u“ F:\\ Workfiles \\\\ u5468 \\ u62a5 \\ forupdate \\ [u'suxl20170821.xlsx']”
does any body knows how to get the files path ??? 有谁知道如何获取文件路径???
you can use listdir to find the paths 您可以使用listdir查找路径
import os
for file in os.listdir("F:\Workfiles\周报\forupdate"):
if file.endswith(".xlsx"):
print(os.path.join("F:\Workfiles\周报\forupdate", file))
or You can use glob 或者您可以使用glob
import glob, os
os.chdir("F:\Workfiles\周报\forupdate")
for file in glob.glob("*.xlsx"):
print(file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.