Linked Questions
93 questions linked to/from How to use to find files recursively?
171 votes
13 answers
353k views
How can I search sub-folders using glob.glob module? [duplicate]
I want to open a series of subfolders in a folder and find some text files and print some lines of the text files. I am using this: configfiles = glob.glob('C:/Users/sam/Desktop/file1/*.txt') But ...
-1 votes
3 answers
508 views
How can I iterate over all files in all folders of one master folder? [duplicate]
So I wrote a Python scrip that would do a certain thing to a certain .txt file: with open("1.txt") as f: for line in f: #DoStuff Now this works for 1 .txt file. I have One master folder, ...
0 votes
1 answer
376 views
Using chdir() to read all csv files in a directory [duplicate]
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....
0 votes
1 answer
223 views
Why glob is not getting files in subfolders [duplicate]
I have following directory structure $ find . ./file1.html ./soquest_glob.py ./dir1 ./dir1/file2.html ./dir2 ./dir2/file3.html (I have added blank lines above to clarify files in different folders)....
-1 votes
1 answer
385 views
Apply script to multiple folders using string in file path [duplicate]
I am new to the programing world and I have hit a snag on a piece of code. What I have: I have a piece of code that identifies all .MP4 files and calculates the size of the files within a directory. ...
0 votes
0 answers
264 views
How can I check if there are any more JSON files remaining in a directory in Python? [duplicate]
I'm iterating through a directory containing a number of JSON files and sub-directories and .txt files. I need to do this until there are no more JSON files remaining in this root directory. How do ...
0 votes
0 answers
199 views
Opening files with a "wildcard" in python [duplicate]
I have a directory set up like this: content/ content/file1-helloworld.txt content/file2myproject.txt content/file3_howareyou.txt And in python I have the following: file = open("content/FILE_NAME....
1 vote
0 answers
170 views
Find and copy files from directories using wildcard [duplicate]
Still new to python so please dont mind the noob question.I have spend some time first researching and trying to figure it out.I have a files that are in directories.The files look like this; A_1_BB_Z....
3 votes
0 answers
161 views
How to search for all files of a particular type in multiple sub-folders using glob? [duplicate]
with open('C:/Users/JDoe/Downloads/rows_to_del.txt', 'r', encoding="utf8") as f: delete_docs = [line.rstrip('\n') for line in f] print(delete_docs) def txtUpdater(): path = "C:/Users/JDoe/Downloads/...
-2 votes
1 answer
41 views
How do I make a loop to go through every folder on my computer and read every file inside it? [duplicate]
I'm making a bit of a stupid program that's supposed to look like a basic operating system in python, except it's just some fancy fake words while it "boots up", then some basic ...
0 votes
1 answer
41 views
How to make python read subfolders [duplicate]
So I got this working, but now I would like some help to make it read folders and subfolders Also how can I make this change multiple files at one time This is what I got going import glob import ...
1010 votes
36 answers
1.7m views
Getting a list of all subdirectories in the current directory
Is there a way to return a list of all the subdirectories in the current directory in Python? I know you can do this with files, but I need to get the list of directories instead.
205 votes
7 answers
144k views
Recursively iterate through all subdirectories using pathlib
How can I use pathlib to recursively iterate over all subdirectories of a given directory? p = Path('docs') for child in p.iterdir(): # do things with child only seems to iterate over the ...
199 votes
4 answers
159k views
What does the double-asterisk (**) wildcard mean?
I've tried the following command but I don't understand the results: ls ** What does ** mean? How should I use it?
102 votes
5 answers
109k views
How to remove a path prefix in python?
I wanted to know what is the pythonic function for this : I want to remove everything before the wa path. p = path.split('/') counter = 0 while True: if p[counter] == 'wa': break ...