0
DIR_PATH = os.path.dirname(os.path.abspath(__file__))

def loop_folder(folder_name):

return 

def get_file_details(path):
     for files in os.listdir(DIR_PATH): 
      listOfFiles = os.listdir('.')  
    for entry in listOfFiles:
        if entry != '.DS_Store':
            if os.path.isdir(entry):
                  loop_folder()
            elif entry.endswith(".csv"):
                print entry

Hello, I want to write a script that loops in a folder and it's sub-folders until it finds a file with .csv and print it.

I want to make a recursion loop function and call it. But I am stuck and I could use some guidance My problem is with the loop function

ghadah
  • 13
  • 9
  • 4
    just use [`os.walk`](https://docs.python.org/3/library/os.html#os.walk) – juanpa.arrivillaga May 30 '18 at 09:54
  • 1
    Possible duplicate of [DLL load failed when importing PyQt5](https://stackoverflow.com/questions/42863505/dll-load-failed-when-importing-pyqt5) – thuyein May 30 '18 at 10:00
  • Possible duplicate of [Python recursive folder read](https://stackoverflow.com/questions/2212643/python-recursive-folder-read) – AntoineLB May 30 '18 at 10:19

1 Answers1

0

This will give you all .csv files in all sub-directories: import os

for dirpath, dirnames, filenames in os.walk("."):
    for filename in [f for f in filenames if f.endswith(".csv")]:
        #do stuff
zipa
  • 27,316
  • 6
  • 40
  • 58