Here is an example of my directory:
Auto ├── Test │ └── Test.csv ├── Test2 │ └── Test2.csv └── new.csv I am trying to read all the csv files in the directory.
Here is my code:
import glob, os os.chdir('C:\\Users\\Me\\Desktop\\Auto') for file in glob.iglob('*.csv'): print(file) This only prints “new.csv” and not “Test.csv” or “Test2.csv”.
I was thinking maybe I could try the directory name as the following:
os.chdir('C:\\Users\\Me\\Desktop\\Auto\\{}') But, this gives me a FileNotFoundFoundError as the system cannot find the directory specified.
Test2supposed to be insideTest, or directly withinAuto? Why are there two separate lines pointing atnew.csv?chdirwould really not be a reasonable approach IMO. As noted in the duplicate or the answer below, you don't have to do anything because theglobmodule can handle this, but even if it couldn't, you should instead use an absolute path and construct it before passing it toglob, don't actually change the working directory