When using fullfile() on Windows, it outputs the path of a file with the backslash (\) as delimiter. If the output is then passed as a format specifier to a function like sprintf (or compose), it runs into error, e.g. sprintf(fullfile('folder', '%d'), nr), because it interprets the blackslash as an escape character.
This function deals with the issue by adjoining file parts using the forward slash (/) as delimiter.
Valerio Rubino (2021). Join fileparts (https://www.mathworks.com/matlabcentral/fileexchange/90476-join-fileparts), MATLAB Central File Exchange. Retrieved .
I crafted this function when I needed to first get the formatSpec and only then "fill" it (inside a loop); therefore, it was less redundant and also more readable to first use this function while outside the loop and then just go with sprintf inside the loop.
I acknowledge it is a very limited scope, but this was useful for me and I thought I may share it with others :)
I don't see why you would do this. You still need to use sprintf to create each part of the path with this function, so why not just flip the two calls: fullfile('folder',sprintf( '%d', nr))?
I would see a benefit if this function would detect format specifiers and apply sprintf on each part.
fulllfile_formatted('%%temp%%','folder%d','subfolder','file_%d.txt',num_dir,num_file) --> '%temp%\folder1\subfolder\file_2.txt'
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!