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

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 :: fill a column based on values in another column pandas 
Python :: how to cut image python 
Python :: how to see if a number is prime in python 
Python :: numpy fill with 0 
Python :: enumarate in python 
Python :: pyqt5 qtextedit change color of a specific line 
Python :: python plot arrays from matrix 
Python :: django start app 
Python :: how to convert unicode to string python 
Python :: all the symbols on a keyboard python list 
Python :: how to declare a class in python 
Python :: How to Use Python Glob Module 
Python :: Python dir() built-in function 
Python :: pickle save dict 
Python :: python plot label value 
Python :: flask dockerize 
Python :: gaussian filter 
Python :: for pyton 
Python :: print list in one line 
Python :: python sys.argv exception 
Python :: os.move file 
Python :: delete last message discord.py 
Python :: resize cmd using python 
Python :: transformers bert 
Python :: python pass 
Python :: perform_update serializer django 
Python :: python dict keys to string 
Python :: sum of prime numbers python 
Python :: creating a bar plot bar | creating a bar chart 
Python :: list all files in folder python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =