python如何獲取資料夾下的所有文件名稱

2021-10-04 03:24:26 字數 834 閱讀 5681

這幾天開始鼓搗深度學習dnn,用的主要是tensorflow的keras框架,然後自己的又噪點太多,(因為這些噪點正負樣本都有影響,所以,強迫症能容忍這個❓?。。。。)

不存在的我跟你講!

我這裡將資料夾下所有的都遍歷一遍,然後對進行濾波操作:

import os

import cv2

import numpy as np

path =

def file_name_find(file_dir):

for root,dirs,files in os.walk(file_dir):

for j in files:

file_name_find("c:/users/hb/desktop/samples/pos")

print(path)

'''上面**就能獲取出所有的檔名稱'''

'''下面的**我進行了高斯濾波之後又儲存成新的'''

img =

gray =

for i in range(0,len(path)):

for i in range(0,len(img)):

num = 0

for i in gray:

cv2.imwrite("c:/users/hb/desktop/samples/positive/"+str(num)+".png", i)

num+=1

如果想要完成兩個功能,就要放一起,如果你只要讀取資料夾下的所有檔名,就不用import cv2

嗯~ o( ̄▽ ̄)o強迫症的世界就是這麼簡單!

看不順眼就搞他?

python如何獲取當前資料夾下所有檔名詳解

前言 os 模組下有兩個函式 os.walk os.listdir 示例 coding utf 8 iwww.cppcns.commport os def file name file dir for rootwldiiulep,dirs,files in os.walwww.cppcns.comk...

Python 獲取資料夾下的檔名

os 模組下有兩個函式 os.walk os.listdir 模組os中的walk 函式可以遍歷資料夾下所有的檔案。os.walk top,topdown ture,onerror none followlinks false 該函式可以得到乙個三元元組 tupple dirpath,dirname...

獲取資料夾下所有檔案

ming xi path r c users administrator.carlos pc desktop 國防專利局 all tables 繳費明細表 彙總的繳費明細表 繳費明細表.xlsx decode utf 8 def get file path file dir,file type xl...