필터 지우기
필터 지우기

up one directory's folder name from current directory

조회 수: 67 (최근 30일)
venkat ta
venkat ta 2020년 8월 25일
답변: Image Analyst 2020년 8월 25일
I have directory path below
/Volumes/GoogleDrive/Shared /Mesure_geo/Temp/delete/AGING/LKG0.3V'
I need to get two string variables
LKG0.3V
AGING
yes I wanna use the current folder name and previous folder name (up one directory to AGING) in MatLab

채택된 답변

Image Analyst
Image Analyst 2020년 8월 25일
See my utility:
%==========================================================================================================================
% Gets the folder one level up. If startingFolder is a filename with an extension it gets the containing folder and the child folder is null.
% Returns null for both if the folder does not exist, and it's not a filename either.
function [parentFolder, childFolder] = GetParentFolder(startingFolder)
parentFolder = []; % Initialize
childFolder = [];
try
if isfolder(startingFolder)
[parentFolder, childFolder, ext] = fileparts(startingFolder);
% Need to append extension for rare cases where deepest folder has a dot in the name.
childFolder = [childFolder, ext];
elseif isfile(startingFolder)
% It's a filename, not a folder. Need to change otherwise childFolder will be returned as the base file name.
[parentFolder, childFolder, ext] = fileparts(startingFolder);
childFolder = []; % No child folder since it's a filename, not a folder name.
end
catch ME
message = sprintf('Error in GetParentFolder():\n%s', ME.message);
uiwait(msgbox(message));
end
return; % from GetParentFolder
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by