adding apostrophe for reading a folder name

I am trying to files in that directory which have folder name as "6 'o' clock".
filefolder = fullfile(dataset_folder,'6 ''o'' clock');
load(fullfile(filefolder,'234.mat');
it gives me this error:
Error using load
Unable to read file 'E:\Data_Sets\Fault\Outer\6 'o' clock\234.mat': no such file or directory.
I am able to read the folders which doesnt have the apostrophe, but not with the apostrophe. how to do it My path in windows is
E:\Data_Sets\Fault\Outer\6 'o' clock\
and i have files from 190.mat to 290.mat in this folder

댓글 수: 6

Please show us the output of this command:
dir 'E:\Data_Sets\Fault\Outer\*clock
David Goodmanson
David Goodmanson 2017년 4월 18일
Hi Raady, is it supposed to be D: or is it supposed to be E: ?
E:\Data_Sets\Fault\Outer\6 'o' clock\ is original path
Raady
Raady 2017년 4월 18일
@Stephen
The command is not working like the u gave me instead I have changed to the current folder and type dir
output is . .. 190.mat 191.mat 192.mat and so on .
I able to run the code if I rename the folder from "6 'o' clock" to 6_o_clock. it means it has some problem in string formatting. By seeing some examples i understood that when the name comes with ' symbol , it should be '' ( 2 times ) to make the matlab read as ' instead of reading it as start and end of string. So I have mentioned as '6 ''o'' clock'. but the problem is as mentioned above.
Stephen23
Stephen23 2017년 4월 18일
편집: Stephen23 2017년 4월 18일
Okay, what are the exact outputs of these commands:
dir E:\Data_Sets\Fault\Outer\
exist('E:\Data_Sets\Fault\Outer','dir')
exist('E:\Data_Sets\Fault\Outer\6 ''o'' clock','dir')
Jan
Jan 2017년 4월 18일
@Raady: Do you understand, what we are asking for? We assume, that your folder is not called "6 'o' clock", but that there are some unexpected characters in the name. Perhaps these are different quotes like ´ or `, or the spaces are not spaces, but invisible non-printable characters. Running my code would reveal this.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2017년 4월 18일

0 개 추천

Check the name twice. Are there any unicode characters in the name?
FileList = dir('E:\Data_Sets\Fault\Outer\6*');
Name = {FileList.name};
for iName = 1:numel(Name)
fprintf('\n%s\n', Name{iName});
fprintf('%d ', double(Name{iName}));
end
Image Analyst
Image Analyst 2017년 4월 18일

0 개 추천

Try this:
quote = 39; % ASCII value for a single quote.
subFolder = sprintf('6 %co%c clock', quote, quote) % Create string: 6 'o' clock
fileFolder = fullfile(dataset_folder, subFolder) % Prepend another folder.
fullFileName = fullfile(fileFolder, '234.mat') % Construct the full file name of the mat file.
% Try to load the file. Warn if it does not exist.
if exist(fullFileName, 'file')
load(fullFileName);
else
errorMessage = sprintf('Error: File not found:\n%s', fullFileName);
uiwait(errordlg(errorMessage));
end

카테고리

도움말 센터File Exchange에서 파일 작업에 대해 자세히 알아보기

태그

질문:

2017년 4월 18일

댓글:

Jan
2017년 4월 18일

Community Treasure Hunt

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

Start Hunting!