Global Index (all files) (short | long) | Local contents | Local Index (files in subdir) (short | long)
FileNameExtended = straddname(FileNameBase, StrExtension, DefaultFileName)
Add a special name to a string/file name This function extends a given string with another string. The main use is in the generation of an extended filename for data files based on a common string and extended by changing contents. The given file name base can be used for specifying the main topic of the data and the extension reflects the current run or similar. The extension is only done, when the filename ends in an underscore. The handling of an path and file extension is done inside the function. See the examples below. Syntax: FileNameExtended = straddname(FileNameBase, StrExtension) Input parameter: FileNameBase- String containing the base of the new filename can include path and extension StrExtension- String containing the extension Output parameter: FileNameExtended - extended string Examples: % Extend the string/filename FN='OptResult_' with another string % ExtStr, when FN is empty, just use the default in DefStr % the extension is only done, when FN ends in '_' >> FN = 'OptResult_'; ExtStr = 'special_name'; DefStr = 'DataFile_'; >> NewName = straddname(FN, ExtStr, DefStr); NewName = 'OptResult_special_name' >> FN = 'dir1\data2\Result_.txt'; ExtStr = 'run4'; DefStr = 'DataFile_'; >> NewName = straddname(FN, ExtStr, DefStr); NewName = 'dir1\data2\Result_run4.txt' % Here the default string in DefStr is used (FN is empty) >> FN = ''; ExtStr = 'run4'; DefStr = 'DataFile_'; >> NewName = straddname(FN, ExtStr, DefStr); NewName = 'DataFile_run4' See also: straddtime