1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| ''' Created on 2011-8-3
@author: Killua @E-mail:[email protected] @Description: '''
import os
def file_path_info(filename): print("OS:" + os.name) print("split:", os.path.split(filename)) print("splitext:", os.path.splitext(filename)) print("dirname:", os.path.basename(filename)) print("basename:" + os.path.basename(filename))
def list_files(directory): stack = [directory] files = [] while stack: directory = stack.pop() for file in os.listdir(directory): fullname = os.path.join(directory, file) files.append(fullname) if os.path.isdir(fullname) and not os.path.islink(fullname): stack.append(fullname) for file in files: print(file)
def main(): list_files("/home/killua")
if __name__ == "__main__": main()
|