%% Convert Filename to Variable Name
% Build a pattern that matches portions of the file between "C:\parent directory\" and the file name extension using lookBehindBoundary and lookAheadBoundary. Extract the matched text.

file = "C:\parent directory\directory of interest\file_of_interest.txt";
pat = lookBehindBoundary("C:\parent directory\") + wildcardPattern + lookAheadBoundary("." + alphanumericsPattern);
name = extract(file,pat)

% Replace whitespace or backslashes these characters with underscores. This insures that the file name is a valid variable name.

name = replace(name,whitespacePattern|"\","_")

% Copyright 2020 The MathWorks, Inc.