Skip to content

Instantly share code, notes, and snippets.

@tsalo
Created March 10, 2015 19:48
Show Gist options
  • Save tsalo/024105d79c7e8815a31d to your computer and use it in GitHub Desktop.
Save tsalo/024105d79c7e8815a31d to your computer and use it in GitHub Desktop.
Removes extra slashes from path string.
function fixedPath = cleanPath(inPath)
% FORMAT fixedPath = cleanPath(inPath)
% Removes extra slashed from inPath.
[filePath, fileName, fileSuffix] = fileparts(inPath);
if isempty(fileSuffix)
splitFile = regexp(filePath, '/', 'split');
else
splitFile = regexp(inPath, '/', 'split');
end
splitFile = splitFile(~cellfun('isempty', splitFile));
fixedPath = '';
for iFolder = 1:length(splitFile)
fixedPath = [fixedPath '/' splitFile{iFolder}];
end
fixedPath = [fixedPath '/'];
if ~isempty(fileSuffix)
fixedPath = [fixedPath fileName fileSuffix];
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment