--When processing files recursively from the directory directly under the directory, use shell commands because you are basically using the Linux environment. ――However, when recursively copying files in an environment that can only be used in the Windows environment, it was very troublesome to use the command prompt, so I will introduce an example of copying using Python.
--Give the copy source path and copy destination path as function arguments
--I think you can give the input and output paths as arguments when executing the file.
--As a file structure, consider the following example
C:/Users/input/ ├ 01 ├ 01_01.jpg ├ 01_02.jpg ├ 02 ├ 02_01.jpg ├ 02_02.jpg
--Copy the above JPG
--Function
import os
import glob
import shutil
def copyfiles(input, output):
ifiles = os.listdir(input)
for s in ifiles:
ifiles_all = input+ "/" + s
fs = glob.glob(ifiles_all + "/*")
for f in fs:
fname = f.split("\\")[-1] #name of file
ofullname = output + "/" + fname
shutil.copyfile(f, ofullname)
input = "C:/Users/input"
output = "C:/Users/output"
copyfiles(input, output)
Recommended Posts