imread error file does not exist

40 ビュー (過去 30 日間)
suha alasheh
suha alasheh 2021 年 3 月 31 日
コメント済み: Walter Roberson 2022 年 8 月 4 日
i want to read the image soso.png so i wrote the following code and kept getting this error:
imgread=imread('c:\ This PC\Downloads\soso.Jpg')
Error using imread>get_full_filename (line 566)
File "c:\ This PC\Downloads\soso.Jpg" does not exist.
  2 件のコメント
DGM
DGM 2021 年 3 月 31 日
Does that file actually have a ".Jpg" extension (case-sensitive)? Just because the file browser says it's a .jpg file doesn't mean that the filename actually has any extension at all. Personally, I have no idea how anyone puts up with a file browser hiding extensions like this. It does nothing but generate ambiguity.
suha alasheh
suha alasheh 2021 年 4 月 2 日
i tried with ".jpg" and without, they both gave the same error :(

サインインしてコメントする。

回答 (3 件)

Kibo
Kibo 2022 年 8 月 4 日
I'm not sure whether you already fixed this issue or not.
The correct path is "C:\Users\YOURUSERNAME\Downloads\soso.jpg"
Try to replace YOURUSERNAME.
There definately no "This PC" folder under C:\.
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 8 月 4 日
A user could deliberately create a "This PC" folder... it just wouldn't be a good idea.

サインインしてコメントする。


Sajid Afaque
Sajid Afaque 2021 年 4 月 2 日
編集済み: Sajid Afaque 2021 年 4 月 2 日
actually the path which you have given is in wrong format
try to remove the space before foldername This PC
imgread=imread('c:\This PC\Downloads\soso.Jpg');
recheck the path once atleast in my PC , This PC is replaced by C:\Users\Downloads

Image Analyst
Image Analyst 2021 年 4 月 2 日
You may have a discrepancy in spelling or spaces in the string. Here, try this more robust way of doing it:
folder = 'c:\ This PC\Downloads';
if ~isfolder(folder)
errorMessage = sprintf('Error: this folder does not exist:\n%s', folder);
uiwait(errordlg(errorMessage));
return;
end
baseFileName = 'soso.Jpg';
fullFileName = fullfile(folder, baseFileName);
if ~isfile(fullFileName)
errorMessage = sprintf('Error: this image file does not exist:\n%s', fullFileName);
uiwait(errordlg(errorMessage));
return;
end
imageArray = imread(fullFileName);
imshow(imageArray);
axes('on', 'image');
Like DGM says, go to your "folder and search options" in File Explorer, click on the View tab, and uncheck the checkbox that says "Hide extensions for known file types". That was just a super dumb choice Microsoft chose when they wanted to make it firendlier and more "mac-like" when all it did was to make it more confusing. Luckily you can undo that to show all extensions.

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by