小甲鱼课后习题,第30课的第2题,为什么要返回上一层目录?
temp1=input('请输入待查找的初始目录:')temp2=input('请输入需要查找的目标文件:')
def file_check(temp1,temp2):
os.chdir(temp1) #改变工作目录
list_ff=os.listdir(os.curdir)#获取当前工作目录的文件名
for each_file in list_ff:
if each_file==temp2:
print os.getcwd()+os.sep+each_file
if os.path.isdir(each_file): #判断是否有多级目录
file_check(each_file,temp2) #递归调用
os.chdir(os.pardir)
file_check(temp1,temp2)
os.chdir(os.pardir) ,请问为什么要加上这行代码,不加上也正能输出正确结果 file_check(each_file,temp2) #递归调用 进入目录,如果是最后是一层
os.chdir(os.pardir)#是不是该返回上一层了,然后在一层一层的返回 ba21 发表于 2017-10-19 19:45
file_check(each_file,temp2) #递归调用 进入目录,如果是最后是一层
os.chdir(os.pardir) ...
谢谢
页:
[1]