MATLAB Answers

How to get the folder of an url?

1 view (last 30 days)
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})
folder{i,1} = getFolderURLFromURLstring(cellArray{i});
list= cellfun(@(x) x(1:end-1), list, 'UniformOutput', false);
function fileName = getFolderURLFromURLstring(url)
temp = strsplit(url, '/');
temp(end) = '';
fileName = strcat(strjoin(temp, '/'), '/');

Accepted Answer

Johnny Cheng
Johnny Cheng on 26 Feb 2021
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:
  1 Comment
Haron Shaker
Haron Shaker on 27 Feb 2021
Thank you very much, Mr. Cheng.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!