Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python open directory and read files

#It doesn't have to be the current directory you can list them in any path you want:
path = '/some/path/to/file'
for filename in glob.glob(os.path.join(path, '*.txt')):
   with open(os.path.join(os.getcwd(), filename), 'r') as f: # open in readonly mode
      # do your stuff
Comment

python open directory and read files

import glob
for filename in glob.glob('*.txt'):
   with open(os.path.join(os.getcwd(), filename), 'r') as f: # open in readonly mode
      # do your stuff
Comment

python open directory and read files

import os
for filename in os.listdir(os.getcwd()):
   with open(os.path.join(os.getcwd(), filename), 'r') as f: # open in readonly mode
      # do your stuff
Comment

PREVIOUS NEXT
Code Example
Python :: discord py color 
Python :: save dataframe to csv 
Python :: colab add library 
Python :: how to encrypt a string python 
Python :: label encoding 
Python :: plt.xticks 
Python :: learningrate scheduler tensorflow 
Python :: python assers 
Python :: pandas create new column and fill with constant value 
Python :: how to remove blank lines from string in python 
Python :: make lists for each 2 items in a list 
Python :: python image to grayscale 
Python :: pil image to numpy 
Python :: Creating a list with list comprehensions 
Python :: pandas map multiple columns 
Python :: how to do http requetss python 
Python :: os.listdir in python 
Python :: how to give column names in pandas when creating dataframe 
Python :: django connection cursor 
Python :: plt change grid color 
Python :: aiohttp get 
Python :: discord bot python add bio 
Python :: lista to txt python 
Python :: sklearn train_test_split 
Python :: how to create a countdown timer using python 
Python :: How do I get the parent directory in Python? 
Python :: find record where dataframe column value contains 
Python :: send message if user is banned discord.py 
Python :: scroll horizontal excel 
Python :: python selenium web scraping example 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =