Skip to content

Instantly share code, notes, and snippets.

@heimoshuiyu
Last active October 14, 2017 00:48
Show Gist options
  • Save heimoshuiyu/d0ee5a8ccf0067a1507f4d00b2028a3d to your computer and use it in GitHub Desktop.
Save heimoshuiyu/d0ee5a8ccf0067a1507f4d00b2028a3d to your computer and use it in GitHub Desktop.
walk_file_function
import os, os.path
def do_dir(file): #What you want to do with the file
pass
def do_file(file): #What you want to do with the
pass
def walk(where): #Walk file and dir in where
for localtion,dirlist,filelist in os.walk(where):
if dirlist:
for dirname in dirlist:
do_dir(os.path.join(localtion,dirname))
if filelist:
for filename in filelist:
do_file(os.path.join(localtion,filename))
if __name__ == '__main__':
walk(os.getcwd()) #Walk in where the workdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment