我正在檢查檔案名 - 'Dev Finance GRM CONS ASPAC_Sales_3069_WI2_2020_GrsSalesAdj_Manual Upload Planning_1000records.csv' 是否存在于路徑中
我在同一個路徑中生成了多個名稱相似的檔案,但在上述情況下生成了一個唯一的 pin ('3069')。此“3069”存盤在唯一變數“upload_pin”中
upload_pin = 3069(我想搜索包含此 upload_pin 的 .csv 檔案是否存在于我的路徑中)
試過這個:
path = r"\\OPCITSNAPADCON2.jnj.com\tm1\cons\grm_aspac\user_in\Manual Upload Current Plan\Archive"
csv_files = glob.glob(os.path(path '/*.csv'))
for filename in csv_files:
if upload_pin in filename:
print(filename)
uj5u.com熱心網友回復:
這對我有用
import os
upload_pin = 3069
for filename in os.listdir():
if filename.endswith(".csv") and filename.find(str(upload_pin))>=0:
print(filename)
uj5u.com熱心網友回復:
嘗試
# get file names of all csv files in the directory
os.chdir('...')
all_csv_files = glob.glob("*.csv")
# provide your pin
upload_pin = 3069
# for each one of your files
# if the file name contains the target pin, print the file name
for file in all_csv_files:
if (str(upload_pin) in file):
print(file)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/336075.html
上一篇:如何隔離熊貓資料框中的部分字串
