Temporary change directory
cdtemp(DIR)
change current directory to DIR, but automatically return to
original directory when the calling function or subfunction
finishes or gets an error.
Basically this function is equivalent with adding next code to your
function:
old_dir = cd(DIR);
C = onCleanup(@()cd(old_dir));
When CDTEMP is used multiple times in the same function or
subfunction, then on exit current directory will be set to the
first orginal directory.
The CLEAR command will also change current directory to the first
original directory.
Example:
Change to new directory and return when the function that uses this
command finishes.
cdtemp('S:\data');
Change to new directory, do your things and return to original
directory.
cdtemp('S:\data');
...
clear
see als cd, onCleanup, clear
Cite As
Peter van den Biggelaar (2024). Temporary change directory (https://www.mathworks.com/matlabcentral/fileexchange/40150-temporary-change-directory), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |