Search code examples
pythonpython-3.xpathoperating-systemfilepath

Why this os loop doesn't print out the full paths of all of the files and just gives some of them?


I've written this to find the paths of all the .aseprite files:

import os
x = 0
print(os.getcwd())
os.chdir("c:/Users/Buğra/")
for docs, subs, files in os.walk(os.getcwd()):
    for f in files:
        if f.endswith(".aseprite"):
            x += 1
            print(x, f, "===", os.path.dirname(docs))

Although it gives all the path of most of them, it doesn't print out the full path of the ones in the Downloads folder.

c:\Users\Bu�ra\Desktop\Kodlama
34 wixard.aseprite === c:\Users\Bu�ra\Desktop\Kodlama
35 boduragac.aseprite === c:\Users\Bu�ra
36 flower.aseprite === c:\Users\Bu�ra
37 painti1.aseprite === c:\Users\Bu�ra
38 painti10.aseprite === c:\Users\Bu�ra
39 painti19.aseprite === c:\Users\Bu�ra
40 painti2.aseprite === c:\Users\Bu�ra
41 painti3.aseprite === c:\Users\Bu�ra
42 painti4.aseprite === c:\Users\Bu�ra
43 painti5.aseprite === c:\Users\Bu�ra
44 painti6.aseprite === c:\Users\Bu�ra
45 painti7.aseprite === c:\Users\Bu�ra

Any idea why?


Solution

  • try this?

    import os
    x = 0
    print(os.getcwd())
    os.chdir("<your dir/path>")
    for docs, subs, files in os.walk(os.getcwd()):
        for f in files:
            if f.endswith(".aseprite"):
                x += 1
                print(x, f, "===", docs)```