为什么这个 os 循环不打印出所有文件的完整路径而只给出其中的一些?
Why this os loop doesn't print out the full paths of all of the files and just gives some of them?
我写这个是为了找到所有 .aseprite 文件的路径:
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))
虽然它给出了大部分文件的所有路径,但它并没有打印出下载文件夹中文件的完整路径。
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
知道为什么吗?
使用
print(x, f, "===", docs)
而不是
print(x, f, "===", os.path.dirname(docs))
试试这个?
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)```
我写这个是为了找到所有 .aseprite 文件的路径:
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))
虽然它给出了大部分文件的所有路径,但它并没有打印出下载文件夹中文件的完整路径。
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
知道为什么吗?
使用
print(x, f, "===", docs)
而不是
print(x, f, "===", os.path.dirname(docs))
试试这个?
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)```