Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Reset the value of Directory[] and DirectoryStack[]
ResourceFunction["ResetDirectoryStack"][] sets the current Directory[] to $InitialDirectory and DirectoryStack[] to an empty list. | |
ResourceFunction["ResetDirectoryStack"][{"dir1","dir2",…}] sets DirectoryStack[] to {"dir1","dir2",…}. | |
ResourceFunction["ResetDirectoryStack"]["cwd",{"dir1","dir2",…}] sets the current Directory[] to "cwd" in addition to setting the directory stack. |
SetDirectory pushes a directory onto the DirectoryStack[]:
In[1]:= |
Out[3]= |
Reset the DirectoryStack[]:
In[4]:= |
Out[4]= |
The current Directory[] and the DirectoryStack[] have returned to their original values:
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Set the DirectoryStack[] to a specific list:
In[7]:= |
Out[7]= |
Traverse the list using ResetDirectory:
In[8]:= |
Out[8]= |
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
Set the current directory along with the directory stack:
In[11]:= |
Out[11]= |
In[12]:= |
Out[12]= |
In[13]:= |
Out[13]= |
Clear the directory stack:
In[14]:= |
Out[14]= |
To reset the directory stack while preserving the current directory, use Automatic:
In[15]:= |
Out[12]= |
In[16]:= |
Out[16]= |
Use All to reset the current directory as well:
In[17]:= |
Out[17]= |
ResetDirectoryStack[] is equivalent to ResetDirectoryStack[All]:
In[18]:= |
Out[12]= |
In[19]:= |
Out[19]= |
By default, ResetDirectoryStack will fail if any of the given directories do not exist:
In[20]:= |
In[21]:= |
Out[21]= |
Use CreateIntermediateDirectories→True to create any missing directories automatically:
In[22]:= |
Out[22]= |
In[23]:= |
Out[23]= |
Use the resource function DirectoryBlock to automatically reset the directory stack after an evaluation:
In[24]:= |
Out[24]= |
In[25]:= |
Out[25]= |
In[26]:= |
Out[26]= |
When setting the directory stack, the final directory must be $InitialDirectory:
In[27]:= |
Out[27]= |
If missing, it will be inserted automatically and produce a warning message:
In[28]:= |
Out[28]= |
In[29]:= |
Out[29]= |
If setting the directory stack to an empty list, the current directory must be set to $InitialDirectory:
In[30]:= |
Out[30]= |
Attempting to set to another directory will result in a warning and $InitialDirectory automatically added:
In[31]:= |
Out[31]= |
In[32]:= |
Out[32]= |
This work is licensed under a Creative Commons Attribution 4.0 International License