I want to copy some pictures into different subdirectories 'test' & 'train' located in a directory 'dataset_dogs_vs_cats' that I created using 'makedirs()' librairy. I am facing an issue with the code below related to the access to the subfolders that I created. I do not understand why the permission is denied. I know that there already are several topics discussing it, but after trying different propositions of solutions (closing all files & directories, runing as admin, set path, etc.), my problem is still not solved. The permission Error: [Errno 13] Permission denied:' still remain. Any option please? Thanks.
Here below is the code, taken from this example:
import os
from os import listdir
from os import makedirs
from shutil import copyfile
from random import seed
from random import random
from numpy import asarray
from numpy import save
from numpy import load
from matplotlib import pyplot as plt
from matplotlib.image import imread
%matplotlib inline
##Creation of subdirectories
dataset_regroup = 'dataset_dogs_vs_cats/'
subdirs = ['train/', 'test/']
for subdir in subdirs:
#creation of labels of subdirectories
labeldirs = ['dogs/', 'cats/']
for label in labeldirs:
newdirectory = dataset_regroup + subdir + label
makedirs(newdirectory, exist_ok = True)
#Fixing the random number generator at the same seed and test ratio
seed(1)
percentage_test = 0.2
#copy the trainig dataset into the corresponding subdirectory
sub_dataset_regroup = 'C:/Users/Wolf/Documents/LETI-LTM/Codes/CNN/dataset_dogs_vs_cats/train/'
for file2 in os.listdir(sub_dataset_regroup):
src = sub_dataset_regroup + '/' + file2
dst_dir = sub_dataset_regroup
if random() < percentage_test:
dst_dir = 'test/'
if file2.startswith('cat'):
dst = dataset_regroup + dst_dir + 'cats/' + file2
elif file2.startswith('dog'):
dst = dataset_regroup + dst_dir + 'dogs/' + file2
copyfile(src, dst)