简体   繁体   English

如何在Python中获取* xlsx文件路径名的字符串?

[英]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.

相关问题 如何从Python中的xlsx文件获取信息? - How to get information from an xlsx file in Python? 如何在python中文件名不完整时获取文件路径 - How to get path to file while the name of file is not full in python 从python中的文件路径获取文件名 - Get file name from File Path in python Python无法获取文件的完整路径名 - Python cant get full path name of file Python:如何从一个XLSX中搜索一个字符串,使其位于另一个XLSX文件中? - Python: How do I search a string from one XLSX to be in another XLSX file? Python。 如何从 xlsx 文件中获取格式样式 - Python. How to get formatting styles from xlsx file 从文件路径 Python 获取带数字的文件夹名和文件名 - Get folder name and file name with digits from file path Python 发送文件作为响应而不是文件路径。 如何在python中发送xlsx文件作为响应 - Send file as a response not file path. How to Send xlsx file as a response in python 如何通过 uniqueid 从 xlsx 文件中提取数据并使用 Python 将该数据写入另一个具有相同列名的 xlsx 文件? - How can I pull data by uniqueid from an xlsx file and write that data to another xlsx file with the same column name using Python? 如何将 XLSX 文件转换为与 XLSX 同名的 CSV? - How to convert XLSX file to CSV with same name as XLSX?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM