好像是QQ更新了版本的原因,以前位于group目录下的缓存图片都到了group2目录下。
但是group2目录下的文件是这样的:
这样找图片很不方便,于是想到用代码实现将所有目录下的图片拷贝到指定目录,方便查看。
代码如下:
import os
import shutil
# 源目录,需替换为个人电脑中group2目录的位置
src_path = ".....\\Image\\Group2\\"
# 目标目录,需替换为个人电脑中存放图片文件的目标目录位置
dest_path = "......\\group2\\"
def get_files(path):
# 列出group2目录下的所有目录名
file_list = os.listdir(path)
# 遍历每一个目录
for file in file_list:
# 获取名字
file_src_path = os.path.join(path, file)
# 如果是文件(即图片),就拷贝到指定保存目录
if os.path.isfile(file_src_path):
file_dest_path = os.path.join(dest_path, file)
shutil.copy(file_src_path, file_dest_path)
# 如果是目录,就再次执行函数
else:
get_files(file_src_path)
get_files(src_path)