Discuss / Python / 作业

作业

Topic source

-- coding: utf-8 --

import os

def search(root = '.', name = ''): for curFile in os.listdir(root): if os.path.isdir(os.path.join(root, curFile)): search(os.path.join(root, curFile), name) elif os.path.isfile(os.path.join(root, curFile)) and name in curFile: print(os.path.join(root, curFile))

if name == 'main': search('C:\Python34', 'server')

题目是查找文件名包含指定字符串的文件,然后并打印出相对路径

你这个不对


  • 1

Reply