I created a list of files in a directory using os.listdir(), and I'm trying to move percentages of the files(which are images) to different folders. So, I'm trying to move 70%, 15%, and 15% of the files to three different target folders.
Here is a slice of the file list:
print(cnv_list[0:5])
['CNV-9890872-5.jpeg', 'CNV-9911627-97.jpeg', 'CNV-9935363-11.jpeg', 'CNV-9911627-15.jpeg', 'CNV-9935363-118.jpeg']
So, I'm trying to send 70% of these files to one folder, 15% of them to another folder, and 15% to a third folder.
I saw this code below in another answer here which addresses how to move files, but not my specific question around percentages of those files: Moving all files from one directory to another using Python
import shutil
import os
source_dir = '/path/to/source_folder'
target_dir = '/path/to/dest_folder'
file_names = os.listdir(source_dir)
for file_name in file_names:
shutil.move(os.path.join(source_dir, file_name), target_dir)