MATLAB: How to remove the file path from an audio file name

audioinfoMATLAB

I'm writing a function that will convolve an audio file with an impulse response, and then write this audio data to a new audio file. Ideally, I'd like to use audioinfo to extract the file names from the input audio files, and then use this info to produce a file name for the output audio file; this would create a file name that illustrates which two files have been convolved together, without adding an extra argument to my function for the output file name.
However, when testing out the audioinfo function, I've found that it includes the file path in the file name (eg. INFO.Filename = 'C:\Users\Robert\Documents\MATLAB\Acoustics\BWH Assignment\Audio\speech.wav'). Using this verbatim would obviously produce an unnecessarily long output file name – is there any way I can remove just the file name itself (ie. 'speech.wav' in this case), or would it just be easier to add an output file name argument to my function?
The code I used to investigate audioinfo was:
INFO = audioinfo('Audio/speech.wav');
INFO.Filename

Best Answer

Try using fileparts():
[folder, baseFileNameNoExt, ext] = fileparts(fullFileName);
baseFileName = [baseFileNameNoExt, ext];
Related Question