“Python berulang melalui file di direktori” Kode Jawaban

Iterasi melalui semua file dalam direktori Python

import os
directory = 'the/directory/you/want/to/use'

for filename in os.listdir(directory):
    if filename.endswith(".txt"):
      #do smth
      continue
    else:
    continue
Bored Coder

Python Loop melalui file di direktori

import os

for filename in os.listdir(directory):
    if filename.endswith(".asm") or filename.endswith(".py"): 
         # print(os.path.join(directory, filename))
        continue
    else:
        continue
Proud Polecat

Python berulang melalui file di direktori

import os

for filename in os.listdir(directory):
    if filename.endswith(".asm") or filename.endswith(".py"): 
         # print(os.path.join(directory, filename))
        continue
    else:
        continue
Fair Fowl

File pembukaan Python Loop dari Direktori

basepath = "pathtodir/DataFiles/"
for filename in os.listdir(basepath):
    if filename.endswith(".log"): 
        print(os.path.join("./DataFiles", filename))

        with open(basepath + filename) as openfile:    
            for line in openfile:
            ........
Elated Elephant

Loop melalui file dalam direktori python

import os

for filename in os.listdir("/path/to/dir/"):
    if filename.endswith(".asm") or filename.endswith(".py"): 
         # print(os.path.join(directory, filename))
        continue
    else:
        continue
Funny Finch

cara mengulang melalui glob.iglob iterator

import glob

globIterator = glob.iglob(path, recursive=True)

run = True
while(run == True):
    try:
        print(next(globIterator))
    except:
        run = False
TheRubberDucky

Jawaban yang mirip dengan “Python berulang melalui file di direktori”

Pertanyaan yang mirip dengan “Python berulang melalui file di direktori”

Lebih banyak jawaban terkait untuk “Python berulang melalui file di direktori” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya