Discuss / Python / 练习二

练习二

Topic source

无所谓ovo

#1 Created at ... [Delete] [Delete and Lock User]

import os

str=input('请输入需要找的文件所包含的字符串:')

path=os.getcwd()    #当前目录 

for root,dirs,files in os.walk(path,topdown=True):

    for name in dirs:

        #print(os.path.join(path,name))

        if not name.find(str)==-1:

            print(os.path.join(path,name))

    for name in files:

        #print('\t',os.path.join(path,name))

        if not name.find(str)==-1:

            print(os.path.join(path,name))


  • 1

Reply