Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python iterate through files

import os

directory = os.fsencode(directory_in_str)
    
for file in os.listdir(directory):
     filename = os.fsdecode(file)
     if filename.endswith(".asm") or filename.endswith(".py"): 
         # print(os.path.join(directory, filename))
         continue
     else:
         continue
Comment

python iterate files

# import required module
import os
# assign directory
directory = 'files'
 
# iterate over files in
# that directory
for filename in os.listdir(directory):
    f = os.path.join(directory, filename)
    # checking if it is a file
    if os.path.isfile(f):
        print(f)
Comment

PREVIOUS NEXT
Code Example
Python :: mongodb aggregate group 
Python :: Splitting training and test data using sklearn 
Python :: how to use function in python 
Python :: keyboardinterrupt python 
Python :: fasttext python 
Python :: seconds to datetime.time 
Python :: create empty numpy array without shape 
Python :: position in array python 
Python :: python list for all months including leap years 
Python :: bucketizer pyspark 
Python :: encrypt string with key python 
Python :: python dictionary default 
Python :: Python program to print even numbers in a list 
Python :: intellij python 
Python :: create qr code in python 
Python :: what is module in python 
Python :: can is slice list with list of indices python 
Python :: np.arange and np.linspace difference 
Python :: how to print a list of strings in python 
Python :: python find digits in string 
Python :: asyncio run 
Python :: how to make exe from.py file 
Python :: python insert list 
Python :: labs fill ggplot2 
Python :: Custom x, y-ticks using plt 
Python :: python sort dict by value 
Python :: list of dataframe to dataframe 
Python :: Support Vector Machine (SVM) classifier 
Python :: raku fib 
Python :: print hexadecimal in python 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =