I would suggest using the FILEPARTS function to parse a file name string. Here is an example:
>> fileString = '\home\matlab\black.txt'; >> [filePath,fileName,fileExtension] = fileparts(fileString) filePath = \home\matlab fileName = black fileExtension = .txt
You can then put the line of the file along with a simple concatenation of lines (only for the file name) or with the FULLFILE function (for an absolute or partial path to the file):
fileString = [fileName fileExtension]; %
Using FULLFILE is simpler and more reliable in terms of running your code on different operating systems, as it will select the appropriate file separator for you ("\" for Windows or "/" for UNIX).
source share