May-09-2018, 02:46 AM
Hello malonn, in that code you have some issues to work with, you can append de base directory to the entry name using the os.joinpath function
for Python 2 you have the scandir function in another module, like this
- The Python Tutor
for Python 2 you have the scandir function in another module, like this
import os import scandir def scanRecurse(baseDir): for entry in scandir.scandir(baseDir): if entry.is_file(): yield os.path.join(baseDir, entry.name) else: yield scanRecurse(entry.path) for i in scanRecurse('D:\\App Back-Ups'): print(i)but in python 3, scandir belongs to the os module
import os def scanRecurse(baseDir): for entry in os.scandir(baseDir): if entry.is_file(): yield os.path.join(baseDir, entry.name) else: yield scanRecurse(entry.path) for i in scanRecurse('D:\\App Back-Ups'): print(i)Remember to fix a bug in one of the yield statements
- The Python Tutor