Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python iterate directory

import os

directory = r'C:Usersadmin'
for filename in os.listdir(directory):
    if filename.endswith(".jpg") or filename.endswith(".png"):
        print(os.path.join(directory, filename))
    else:
        continue
Comment

python loop through directory

import os

for filename in os.listdir(directory):
	print(filename)
Comment

iterate through directories in python

import os

dir = os.fsencode(filename='img') # here 'img' should be replaced with
									# desired directory

lst = []

for items in os.listdir(dir):
    lst.append(items)
print(lst)
Comment

PREVIOUS NEXT
Code Example
Python :: how to simulate a key press in python 
Python :: get IP address python 
Python :: install streamlit 
Python :: continue reading lines until there is no more input python 
Python :: split validation set 
Python :: python how to count the lines in a file 
Python :: use incognito in selenium 
Python :: django admin create superuser 
Python :: minimal flask application import 
Python :: txt to list python 
Python :: cv2 crop image 
Python :: code how pandas save csv file 
Python :: matplotlib log 
Python :: auto datetime in django models 
Python :: how to shuffle dictionary python 
Python :: python reimport module after change 
Python :: how to make a tkinter window 
Python :: get list of unique values in pandas column 
Python :: index to datetime pandas 
Python :: getting cursor position in py game 
Python :: check if special character in string python 
Python :: pyqt drag and drop files 
Python :: get current date and time with python 
Python :: save machine learning model 
Python :: change date format python 
Python :: disable csrf token django 
Python :: get date and time in python 
Python :: python auto module installer 
Python :: change the current working directory in python 
Python :: power set python 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =