python file directory

"""
Use python to obtain the specified type file excel in a certain path folder and subfolders in batches, and store them according to the specified path
"""

import them
import shutil

file_excel = []

path = os.getcwd()
path_listdir = os.listdir(path)

for s in path_listdir:
    path_excel = os.path.join(path, s) # Add the file name to the current file path
    if os.path.isfile(path_excel): # If it is a file
     #   print(os.path.splitext(newdir)[0])
      #  print(os.path.splitext(newdir)[1])

        if os.path.splitext(path_excel)[1] == ".xlsx": # If the file has a suffix of ".pdb"
            file_excel.append(path_excel)
         #   print(soundfile)
    elif os.path.isdir(path_excel): # If it is a path
        continue

#for i in range(len(soundfile)):
   # print(soundfile[i])
#print(len(soundfile))

#print(soundfile)


for i in range(len(file_excel)):

    path_dir = os.path.split(file_excel[i])[0]
    print(path_dir)
    path_file = os.path.split(file_excel[i])[1]
    print(path_file)
  #  print(path_1)
    filename = path_dir + '/' + path_file
    filename_bak = path + '/ bak /' + path_file
    shutil.copyfile(filename, filename_bak)
  #  print(str(i) + '/' + str(len(soundfile)))


Guess you like

Origin blog.csdn.net/jidawanghao/article/details/112506160