Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create a file path relative to a given directory
ResourceFunction["RelativePath"][path] gives a string corresponding to path relative to the current Directory[]. | |
ResourceFunction["RelativePath"][path1,path2] gives a string corresponding to path2 relative to path1. |
Get a file path specification relative to another:
| In[1]:= |
| Out[1]= |
Get a path name relative to the current directory:
| In[2]:= |
| Out[2]= |
| In[3]:= |
| Out[3]= |
| In[4]:= |
| Out[4]= |
Path names can be given as a file:// URI:
| In[5]:= |
| Out[5]= |
Use a mix of file specifications:
| In[6]:= |
| Out[6]= |
| In[7]:= |
| Out[7]= |
| In[8]:= |
| Out[8]= |
File objects are also supported:
| In[9]:= |
| Out[9]= |
Get a relative path using cloud objects:
| In[10]:= |
| Out[10]= |
If a cloud object is given with CloudObjectNameFormat set as "UUID", RelativePath can still work if the file exists:
| In[11]:= |
| Out[11]= |
| In[12]:= |
| Out[12]= |
Specify a different operating system for path name formatting:
| In[13]:= |
| Out[13]= |
| In[14]:= |
| Out[14]= |
The single-argument form gives paths relative to the current directory:
| In[15]:= |
| Out[15]= |
| In[16]:= |
| Out[16]= |
Get the absolute path using AbsoluteFileName:
| In[17]:= |
| Out[17]= |
Get the absolute path using ExpandFileName:
| In[18]:= |
| Out[18]= |
Return to the original directory:
| In[19]:= |
| Out[19]= |
RelativePath[NotebookDirectory[],path] is a partial inverse for the resource function NotebookRelativePath:
| In[20]:= |
| Out[20]= |
| In[21]:= |
| Out[21]= |
Using Windows paths with OperatingSystem→"Unix" will produce strange results:
| In[22]:= |
| Out[22]= |
This work is licensed under a Creative Commons Attribution 4.0 International License