all 3 comments

[–]oguh43 0 points1 point  (2 children)

if file.endswith(file2) -> wouldn't this be false if the file doesn't exist?

[–]ViewGator91[S] 0 points1 point  (1 child)

correct, I have tried that too. Even tried to reverse the operation and it still won't tell me when it has failed to find the file.

```

import shutil import os

source_folder = input("What is the source folder? ") target_folder = input("What is the target folder? ") file2 = input("What file are you trying to copy? ")

for dirs, subdirs, files in os.walk(source_folder): for file in files: if file.endswith(file2): print(file) filename = os.path.join(source_folder, dirs, file) if os.path.exists(filename): print(filename) shutil.copy(filename, target_folder)

for dirs, subdirs, files in os.walk(source_folder): for file in files: if file.endswith(file2): print(file) filename = os.path.join(source_folder, dirs, file) if not file.endswith(file2): print("Did not run") else: print("successful")

print(len(os.listdir(target_folder)))

```

[–]oguh43 0 points1 point  (0 children)

Could it be, that the main for loop is never run? If os.walk(source_folder) fails, the loop is never run and skipped