Dani
Dani

Reputation: 41

File Write Permission Issue in Matlab

I've been trying to write image files to the specified folder, but I always receive this error:

Unable to open file "C:\Users\Dani\Desktop\code_version_1.0\myImages" for writing. You may not have write permission.

Is there a way to fix this? Thanks.

for i=1:numberOfFiles 
    filename=fileList{i};
img=imread(filename,'jpg');
image = imresize(img, [150,150]);

folder='C:\Users\Dani\Desktop\code_version_1.0\myImages';
  if ~exist(folder,'dir')
    mkdir(folder);
  end
imwrite(image,folder,'jpg');

end

Upvotes: 1

Views: 6174

Answers (3)

deepLDoc
deepLDoc

Reputation: 11

Be sure to check if the folder exists or not:

folder='C:\Users\Dani\Desktop\code_version_1.0\myImages';

If it doesn't exist ,folder wont be created automatically and will give the same error :You may not have write permission.

Upvotes: 0

user813853
user813853

Reputation:

How about using the imwrite like this :

imwrite(image,'C:\Users\Dani\Desktop\code_version_1.0\myImages\image.jpg');

you can after append things as you like. check this link

Upvotes: 0

Setsu
Setsu

Reputation: 1228

Your call to imwrite has an invalid second parameter. You gave it a folder when it is asking for a file path.

Here's a possible work-around:

outfile = fullfile(folder, 'output.jpg');
imwrite(image, outfile, 'jpg');

Upvotes: 2

Related Questions