0

looking for an extension to my code below, so when the condition is not met files will be moved to "ERROR" folder. Anyone who can help? Thank you :-)

source = '/Users/XY/Desktop/OUT'
destination = '/Users/XY/Desktop/IN'

allfiles = glob.glob(os.path.join(source, '*S*'), recursive=True)
print("Files to move", allfiles)

for file_path in allfiles:
    dst_path = os.path.join(destination, os.path.basename(file_path))
    shutil.move(file_path, dst_path)
    print(f"Moved {file_path} -> {dst_path}")

I tried to search on google but without luck.

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34

1 Answers1

-1
for file_path in allfiles:
    if some_condition:
        dst_path = os.path.join(destination, os.path.basename(file_path))
    else:
        dst_path = os.path.join(error_folder, os.path.basename(file_path))
    shutil.move(file_path, dst_path)
    print(f"Moved {file_path} -> {dst_path}")
John Gordon
  • 29,573
  • 7
  • 33
  • 58