-2

Not searching for stuff in a text file, but searching for every text file within the same folder as the main python shell. Is there any way to do this?

  • 1
    Yes, was there any particular problem when you tried to do this? – mkrieger1 Nov 30 '20 at 12:43
  • 1
    Does this answer your question? [Find all files in a directory with extension .txt in Python](https://stackoverflow.com/questions/3964681/find-all-files-in-a-directory-with-extension-txt-in-python) – mkrieger1 Nov 30 '20 at 12:44

1 Answers1

0

here is an answer using os.walk()

for _, _, files in os.walk(os.getcwd()):
  for file in files:
    print(file)

this will print all the files in the current directory. The os.getcwd() getsthe current folder and os.walk() returns multiple parameters, but the one you want is the last one. Go https://www.tutorialspoint.com/python/os_walk.htm for more information on os.walk()

Shark Coding
  • 143
  • 1
  • 10