终于解决文件重定向的问题

"""
用python批量获取某路径文件夹及子文件夹下的指定类型文件excel,并按指定路径进行存储
"""

import os
import os
import win32com.client as win32
import shutil


filelist_same = []

path_same_head = os.getcwd()
path_same_rear = 'bak'

path_same = path_same_head + '/' + path_same_rear


os.chdir(path_same)    #若想解决定向文件夹内容的打开,需要先重定向至指定文件夹

myfile = '2.xlsx'


if os.path.exists(myfile):      //剩下的事情就很简单了,判断有没有相同的文件,用exists方法,减轻了使用for循环的压力
    print(myfile)








'''



############转换前的文件夹
filelist_trans = []
path_trans = os.getcwd()           #转换前程序所在文件目录
print(path_trans)
pathlist_trans = os.listdir(path_trans)
print(pathlist_trans)




############需要同步的文件夹

filelist_same = []

path_same_head = os.getcwd()
path_same_rear = 'bak'

path_same = path_same_head + '/' + path_same_rear


print(path_same)
pathlist_same = os.listdir(path_same)


print(pathlist_same[0],pathlist_same[1],pathlist_same[2])
#print(os.listdir(str(pathlist_same)))









############替换的文件夹


filelist_scan = []
path_scan = str(os.getcwd() ) + '/bak/'
print(path_scan)
pathlist_same = os.listdir(path_trans)







for trans in pathlist_trans:
    filelist_trans = os.path.join(path_trans, trans)  # 将文件名加入到当前文件路径后面
    if os.path.isfile(filelist_trans):  # 如果是文件
        if os.path.splitext(filelist_trans)[1] == ".xls":  # 如果文件是".xls"后缀的
            for same in pathlist_same:
                filelist_same = os.path.join(path_same, same)  # 将文件名加入到当前文件路径后面
'''

猜你喜欢

转载自blog.csdn.net/jidawanghao/article/details/112602118