I'm trying to do the same as in this question: Copy files from multiple specific subfolders.
But none of the answers work for me at all. When I execute the py in my Windows cmd it doesn't even go into the loops, as I receive no print()
line in the cmd window after executing.
I've tried this solution which copies the files from the directory but ignores all subfolders in that directory entirely.
I have tried looking into shutil
but I don't think I can use it for my case because of the subfolders? It's really important that I don't keep the subfolder structure but just move all the files into one directory.
This is what I have right now but the output unfortunately keeps the folder structure:
import shutil
import os
# Define the source and destination path
source = "d:\\test"
destination = "d:\\test\SubfolderB"
# code to move the files from sub-folder to main folder.
files = os.listdir(source)
for file in files:
file_name = os.path.join(source, file)
shutil.move(file_name, destination)
print("Files Moved")