I'm having trouble with SetDirectory. Practically, I need to get the following code working:
SetDirectory[StringJoin[NotebookDirectory[], "..\\", "txt_Files\\"]];
<< "2_Vectors_Linear_Combinations.txt";
where the notebook that is running is in a directory, /home/name/Mathematica/project, whose parent directory contains the map txt_Files which contains 2_Vectors_Linear_Combinations.txt. It seems to me that the code is perfectly suited for exactly this situation (I'm trying to run code I did not write, but the map/file structure should be the same and I'm pretty sure the original can't have been this bugged.). Yet the output is:
"Cannot set current directory to \
"/home/name/Mathematica/project/..\\txt_Files \\ "
There was a mistake in my question. However, it speaks to the intelligence of the answerers that the question still got interpreted correctly and answered correctly. I corrected the question so that it really matches the anwsers.
Answer
The reason for the error is the fact that only Windows uses backslash "\"
as a separator in paths. All other systems use forward slash "/"
. From the error you get it is clear that you are using either Linux or Mac, so you should stick to the forward slash notation. Normally, Windows software allows forward slash usage too (MMA included), so the following solution works universally:
SetDirectory[StringJoin[NotebookDirectory[], "../", "txt_Files/"]];
Comments
Post a Comment