Effacer les filtres
Effacer les filtres

up one directory's folder name from current directory

67 vues (au cours des 30 derniers jours)
venkat ta
venkat ta le 25 Août 2020
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

Réponse acceptée

Image Analyst
Image Analyst le 25 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by