Relative paths for portable math laptops

I cannot find how to use relative paths in math. My directory structure is simple.

Import["G:\\Research\\Acc and Vel Runs\\5-24\\Mathematica\\Data\\250 \
Acc.xls"][[1]] // TableForm  

This demonstrates the path of the Absolute using the insert path from the menu. I want this laptop to be portable. I want to give someone the Mathematica directory, and I want them to be able to run the code. I do not want the paths to be interrupted because it will be running on another machine. Basically, I just want to use a relative path, starting from the Mathematica level shown above.

+5
source share
2 answers

Mathematica Directory[], - , SetDirectory[]. ReserDirectory[] , DirectoryStack[].

.

,

SetDirectory[NotebookDirectory[]]

NotebookDirectory, Front End .

(Directory[]), Import["data/somedata.txt"].

: / Windows/Linux/Mac. , / , FileNameJoin.

+5

.

SetDirectory[
  FileNameJoin[{$InitialDirectory, "dir1", "dir2"}]];
Quiet[Close["Log.txt"]];
logStream = Quiet[OpenWrite["xmlAreaTagsLog.txt"]];
xmlDoc = Import["XmlData.xml"];

$InitialDirectory, .nb FileNameJoin, .

+2

All Articles