Azzera filtri
Azzera filtri

up one directory's folder name from current directory

67 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Image Analyst
Image Analyst il 25 Ago 2020
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

Più risposte (0)

Categorie

Scopri di più su Search Path in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by