Temporary change directory

Change directory and return to original when calling function finishes or exits with an error.
다운로드 수: 225
업데이트 날짜: 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