Tag Info

New answers tagged


I realise that this is an old question but I think the following option should also be considered: SetDirectory[NotebookDirectory[]]; Adding this line at the beginning of your notebook will essentially tell Import to look for your file in a path relative to where your notebook is saved. This method obviously only works after the notebook has been saved!


Played around a bit and got to a point where I think I can let you finish it off (and make it more "automatic" and syntactically pleasing). file = "/path/to/file/JCO1DADAP_0000" For an unformatted Fortran 77 file I usually start by opening the stream an looking at the first "Integer32". This will determine how many bytes the record uses. str = ...


Leonid Shifrin's implementation of a trie can be used for this purpose. It is available both for lists and for associations. For associations: ClearAll[makeTreeAssoc]; makeTreeAssoc[wrds : {__String}] := Association@makeTreeAssoc[FileNameSplit /@ wrds]; makeTreeAssoc[wrds_ /; MemberQ[wrds, {}]] := makeTreeAssoc[DeleteCases[wrds, {}]]; makeTreeAssoc[wrds_] ...


First off, a more compact form of filesInDir: fileTree[f_, d_] /; DirectoryQ[f] && d > 0 := FileNameTake[f] -> (fileTree[#, d - 1] & /@ FileNames[___, f]) fileTree[f_, _] := FileNameTake[f] Example usage: fileTree[$UserBaseDirectory, 2] (* "Mathematica" -> {"ApplicationData" -> {"CCompilerDriver", "DeviceFramework", ...


Update: much simpler now. If this works right I think I would consider it superior. Update 2: I attempted to add specific handling of files and directories. Please tell me if this appears to work and produce a format that is acceptable to you. fn[x : {___, {_, __}, ___}] := Normal @ GroupBy[x, First -> Rest, fn] fn[x_List] := Join @@ x files = ...


At the risk of betraying how long I've been using Mathematica, the method I'm accustomed to uses StringForm[] (in conjunction with ToString[] since the output of that function, nonintuitively, is not a string): file[i] = 1; OpenWrite[ToString[StringForm["/Users/Home/Desktop/`1`.doc", file[i]]]]


Just another way, with Templates so only for V10+: The following can be done without FileNameJoin but it is a good habit to use it: file[i] = 1; TemplateApply @ FileNameJoin[{$HomeDirectory, "Desktop", "<*file[i]*>.doc"}] ...Desktop\1.doc "<**>" is TemplateExpression


I'm sure this is a duplicate but to give you a quick answer here's a community wiki post: Use ToString and StringJoin to form your argument: file[i] = 1; "/Users/Home/Desktop/" <> ToString @ file[i] <> ".doc" "/Users/Home/Desktop/1.doc" Also look at FileNameJoin.


Use Export["data1.mat", WW1] Export["data2.mat", WW2] Is that what you want? Or combined them into a single matrix using Mathematica, then export the whole matrix. But without the double quotes.

Top 50 recent answers are included