Python/Bash 遍歷文件夾

import os

infiles = list() # the absolute path we want
indir   = './root_data/'

for root, dirs, files in os.walk(indir):
    for filename in files:
        infiles.append(os.path.join(root, filename))

 

 

#!/bin/bash 

PROCESS_NUM=0
function ergodic(){  
    for file in ` ls $1 `  
    do  
        if [ -d $1"/"$file ]   
        then  
             ergodic $1"/"$file  
        else  
             echo "$1/$file" 
             PROCESS_NUM=$[$PROCESS_NUM+1]
             echo $PROCESS_NUM
        fi  
    done  
}  

INIT_PATH="/home/data"  
ergodic $INIT_PATH 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章