MATLAB: Warning: Escape sequence ‘ ‘ is not valid. See ‘help sprintf’ for valid escape sequences

path separatorssprintf troubleswindows slashes

Im trying to create a function that changes the destination folder for some data put into a text file, trouble is that when I try to input an address such as J:\My_Documents\MATLAB into an inputdlg box, and then use sprintf on the answer so that it can be used in
filename = fullfile('Destination','Filename.txt');
sprintf thinks that the \'s in the destination name mean things like \n and \t so it gives me an error saying:
Warning: Escape sequence 'M' is not valid. See 'help sprintf' for valid escape sequences.
and sprintf itself only outputs 'J:' and not the whole destination name is there anyway I can I can change a written answer from an inputdlg box to a useful form for my purpose that doesn't try to do any unwanted formatting on it?

Best Answer

Just avoid the situation in the first place . Use forward slashes /. Windows understands them just fine - no problem whatsoever. Perhaps that's not widely known, but yes, Windows is perfectly happy to use /, at least in MATLAB and Windows Explorer. You don't need to use backslashes at all, so don't.