필터 지우기
필터 지우기

How to get the folder of an url?

조회 수: 4 (최근 30일)
Haron Shaker
Haron Shaker 2021년 2월 26일
댓글: Haron Shaker 2021년 2월 27일
Hey guys,
I wrote this this to get the folder of all the url's stored in 'founded_medicine_folder_ohne.xls' (see atachment). So far, this works. But I got the problem that this code also deletes a slash in 'https//:...' which should not be the case (after: 'https/:...'). How can I avoid that?
cellArray = readcell('founded_medicine_folder_ohne.xls');
folder = {};
for i= 1:size(cellArray,1)
%get folder
if ismissing(cellArray{i})
else
folder{i,1} = getFolderURLFromURLstring(cellArray{i});
end
list= cellfun(@(x) x(1:end-1), list, 'UniformOutput', false);
end
writecell(folder,'founded_medicine_folder.xls')
function fileName = getFolderURLFromURLstring(url)
temp = strsplit(url, '/');
temp(end) = '';
fileName = strcat(strjoin(temp, '/'), '/');
end

채택된 답변

Johnny Cheng
Johnny Cheng 2021년 2월 26일
There is a easier way to get Folder URL in getFolderURLFromURLstring(url):
fileName = url(1: find(url =='/', 1,'last'))
where find() get you last index of '/' in url: https://www.mathworks.com/help/matlab/ref/find.html
  댓글 수: 1
Haron Shaker
Haron Shaker 2021년 2월 27일
Thank you very much, Mr. Cheng.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by