1
は私が見えファイル構造を持つファイル:私はそれを見つけるまでツリーを走査するために私達os.walk(?またはより適切なもの)にしたいPythonの:特定のディレクトリにos.walkなど
|num_1
|----|dir1
|--------|dir2
|------------|dcm
|----------------\file_1
|----------------\file_2
|----------------\file_n
|num_2
|----|dir1
|--------|dcm
|------------\file_1
|------------\file_n
|num_n
ディレクトリ "dcm"。 dcmはさまざまなレベルのツリーにあります。
これは私が持っているものです。ありがとう!
import dicom
import re
import os
dcm = []
PATH = "C:\foo"
#find the directory we want to get to, save path
for path, dirs in os.walk(PATH):
for dirname in dirs:
fullpath = os.path.join(path,dirname)
if "dcm" in dirname:
#copied this first_file line - just want a fast and easy way to grab ONE file in the dcm directory
#without reading any of the others (for time reasons)
first_file = next((join(path, f) for f in os.listdir(path) if isfile(join(path, f))),"none")
fullpath = os.path.join(fullpath,first_file)
dcm.append(fullpath)