2006年11月02日 星期四 13:05
def subfiles(d):
r = []
stack = [([], d)]
while stack:
p, n = stack.pop()
if os.path.isdir(n):
for s in os.listdir(n): #listdir()函数的功能是返回一个列表,里面包含指定目录下的所有文件名和目录名
if s not in ignore and not s.startswith('.'): #文件名不在'.'开头,和不在忽略列表中就执行
stack.append((p + [s], os.path.join(n, s)))
else:
r.append((p, n))
return r
======= 2006-11-02 09:26:00 您在来信中写道:=======
>因为有近万张图片分布在3000多个子目录中,要批量重命名这些文件。求大家帮个忙。
>
>第一就是遍历子目录。
>第二是找到的图片文件符合条件的重命名。
>
>找了半天手册,对文件操作竟然就只找到打开、关闭、读、写,重命名这类的目录操作没找到。哪位知道帮个忙。先谢了。
>_______________________________________________
>python-chinese
>Post: send python-chinese在lists.python.cn
>Subscribe: send subscribe to python-chinese-request在lists.python.cn
>Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>Detail Info: http://python.cn/mailman/listinfo/python-chinese
= = = = = = = = = = = = = = = = = = = =
writer15
writer15在163.com
2006-11-02
Zeuux © 2025
京ICP备05028076号