How to move files from one directory to another in Python
0
1282
The following code will help you if you want move files/folders from one folder or directory to another.
For example you have the following list of files/folders in directory "C:\codes" (source) and you want to move all the files/folders to a source directory "C:\codes_new"
Before move:
Source Directory:
Destination Directory:
FInd the code below
import shutil
import os
source_directory = 'C:\codes\\'
destination_directory = 'C:\codes_new\\'
files = os.listdir(source_directory) # find all files
for f in files: # Move files one by one to destination_directory
src = os.path.join(source_directory, f)
dst = os.path.join(destination_directory, f)
shutil.move(src, dst) # Move files
Once you run the above code, all the files and folders will move from "C:\codes" to "C:\codes_new" . Noe check out folders below
Comment here