""" Use python to obtain the specified type of file excel in a certain path folder and subfolders in batches, and store them according to the specified path """ 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) #If you want to solve the opening of the targeted folder content, you need to redirect to the specified folder first myfile = '2.xlsx' if os.path.exists(myfile): //The rest is very simple, judge whether there are the same files, use the exists method to reduce the pressure of using for loop print(myfile) ''' #### ########Folder before conversion filelist_trans = [] path_trans = os.getcwd() #File directory where the program is located before conversion print(path_trans) pathlist_trans = os.listdir(path_trans) print(pathlist_trans) ###########Folder to be synchronized 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_s0) print(pathlist, path_same) 1],pathlist_same[2]) #print(os.listdir(str(pathlist_same))) ############Replaced folder 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) # Add the file name to the current file path if os.path .isfile(filelist_trans): # If it is a file if os.path.splitext(filelist_trans)[1] == ".xls": # If the file is with the suffix ".xls" for same in pathlist_same: filelist_same = os.path.join(path_same, same) # Add the file name to the back of the current file path '''
Finally solved the file redirection problem
Guess you like
Origin blog.csdn.net/jidawanghao/article/details/112602118
Recommended
Ranking