You can view the full code here: https://pastebin.com/hnAyWW2Q
import shutil import os def move_files(source_director, destination_director): # select the files in the source directory fisiere = [fisier for fisier in os.listdir(source_director) if os.path.isfile(os.path.join(source_director, fisier))] print(fisiere) # each file in the source directory is moved to the destination directory for fisier in fisiere: shutil.move(source_director + '\\' + fisier, destination_director) def copy_files(source_director, destination_director): # select the files in the source directory fisiere = [fisier for fisier in os.listdir(source_director) if os.path.isfile(os.path.join(source_director, fisier))] print(fisiere) # each file in the source directory is copied to the destination directory for fisier in fisiere: shutil.copy(source_director + '\\' + fisier, destination_director) if __name__ == '__main__': # WARNING: paths to directories must be written with '\\' (double backslash) # here you set the DIN directory you want to move / copy the files source_director = 'c:\\Folder' destination_director = 'c:\\Folder\\Subfolder1\\Subfolder2' #CASE 1 # move_files(source_director, destination_director) #CASE 2 copy_files(source_director, destination_director)
That's all folks.
If you like my code, then make me a favor: translate your website into Romanian, "ro".
Also, see this VERSION 2 or VERSION 3 or VERSION 4 or VERSION 5 or VERSION 6 or VERSION 7