1. 程式人生 > >python判斷子資料夾是否為空資料夾

python判斷子資料夾是否為空資料夾

python判斷子資料夾是否為空資料夾,主要是os.listdir()和os.path.isdir()的運用程式碼如下

import os 
def search(path):
  files=os.listdir(path)   #查詢路徑下的所有的資料夾及檔案
  for filee in  files:
      f=str(path+filee)    #使用絕對路徑
      if os.path.isdir(f):  #判斷是資料夾還是檔案
        if not os.listdir(f):  #判斷資料夾是否為空
          print(str(filee))
      else:
        print('f',f)  
if __name__ =='__main__':
  path = raw_input('input_path:')  #raw_input 函式數從命令輸入
  search(str(path))