Temporary change directory

Change directory and return to original when calling function finishes or exits with an error.
225.0 次下载
更新时间 2013/2/4

查看许可证

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

引用格式

Peter van den Biggelaar (2024). Temporary change directory (https://www.mathworks.com/matlabcentral/fileexchange/40150-temporary-change-directory), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2008a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Search Path 的更多信息
标签 添加标签
cd

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0