python 檔案操作知識總結: 獲取當前路徑
阿新 • • 發佈:2019-01-31
1. python
獲取當前所在路徑:
os.getcmd()
獲取當前路徑下的檔案數:
方法一:(已驗證)
sum([len(files) for root,dirs,files in os.walk(dir)])方法二:(未驗證)
count =0
for filename in os.listdir(os.getcmd()):
count += 1
1. python
獲取當前所在路徑:
os.getcmd()
獲取當前路徑下的檔案數:
方法一:(已驗證)
sum([len(files) for root,dirs,files in os.walk(dir)])方法二:(未驗證)
count =0
for filename in os.listdir(os.getcmd()):
count += 1