I wish to avoid os.walk, i am using a recursive function to read files and folders and store files to a dictionary
I got rid of the os.chdir but for some reason function is now joining path + file as well and its generating an error :
WindowsError: [Error 267] The directory name is invalid: ‘c:\data\foo\notes\*.*’
Its reading folder foo and it joined path whit foo and file notes.txt instad of foo + libary folder
This seems to work for me
Still I am not sure why you use the set root. I think the purpose is to keep all the directories when you have the same file in two directories. But it doesnt work: each update deletes the stored values for repeated keys (file names).
Here you have a working code, using a defaultdict /you can do the same with an ordinary dictionary (as in your code) but using defauldict you dont need to check if a key has been initialized before:
Edit: Relative to the comment from @hughdbrown:
If you update data with
data.update(fileRead(path).items())you get tthis when calling forfileRead("c:/python26/programas/pack")in my computer (now in py26):Note that files that are repeated in several directories (copia.py) only show one of those directories, the deeper one. However all the directories are listed when using: