Maybe the question is not clear, here I try to state it in more detail: I have a folder named project
, for instance. In it I have two folders, one is named code
, the other is named data
. In the code
folder, I have two code files: one is testCode.nb
, the other is testCode.m
, these two files always synchronized (have the same contents). What the code does is quite simple, it export a list to a file named test.txt
, which I require it to locate in the data
folder. How can I achieve this?
If in the code files I have:
lst={{1,Pi},{2,2 Pi}};
SetDirectory["../data"];
Export["test.txt",lst//N,"Table"];
The code run as script .m
file in the terminal (on ubuntu linux) pass but failed in notebook. The error is:
SetDirectory::cdir: Cannot set current directory to ../data. >>
data
which is one level up to the current code directory, with the same code both in notebook interface and script interface, doing them seperately is easy. Please see my edited question. $\endgroup$I just need to export the data to the folder data which is one level up to the current code directory
I must be missing something. If you can find out the current code directory (which is what the answer linked to shows), then you know the folder above it. So I do not know what is the issue. You also do not have to set directory to save to it. You can just construct the file path. $\endgroup$c:\my_folder\my_code
then the data directory will bec:\my_folder\data
. Right? $\endgroup$