English 中文(简体)
数学中便携式笔记本的相对路径
原标题:Relative paths for portable notebooks in mathematica

我找不到数学中如何使用相对路径。 我的目录结构很简单 。

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

此路径通过使用菜单中的插入路径来显示绝对路径。 我希望这本笔记本能够被移动。 我想给某人“ 数学” 目录, 我希望他们能够运行代码。 我不想让路径中断, 因为路径将运行在不同的机器上。 基本上我只想使用从上面显示的数学水平开始的相对路径 。

最佳回答

在数学中,您可以使用 timinary[] 获得当前目录,也可以使用 set Staminy[] 将其设置为其他目录。您可以使用 reer timory[] 回到最后一个位置,或者使用 titutyStack[] 检查所有先前的位置。

文件这里

您可以将当前目录设置为笔记本使用的目录

SetDirectory[NotebookDirectory[]]

注目目录 要工作, 您必须使用前端, 笔记本必须保存 。

您总是可以使用与当前目录相对的路径( timinaly[] ),例如 import[""Data/ somedata.txt"]

关于目录分隔符:所有 Windows/Linux/Mac 上的 < code>/ 将永远有效。 在输入相对路径名称时, 只需使用 < code>/ 便携性比 < code> FileNameJoin 更容易得多。

问题回答

我通常这样做。

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

使用 $Intiative 日志为您获取.nb 目录, 使用 FileNameJoin 允许您相对访问 。





相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签