# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

# cd

Change current folder

## Syntax

cd
cd newFolder
oldFolder = cd(newFolder)

## Description

example

cd displays the current folder.

example

cd newFolder changes the current folder to newFolder. Folder changes are global. Therefore, if you use cd within a function, the folder change persists after MATLAB® finishes executing the function.

example

oldFolder = cd(newFolder) returns the existing current folder to oldFolder, and then changes the current folder to newFolder.

## Examples

collapse all

Change the current folder to the featured examples folder for MATLAB R2016b, assuming that version is installed on your C: drive.

cd 'C:\Program Files\MATLAB\R2016b\examples\matlab_featured'

Change the current folder from C:\Program Files\MATLAB\R2016b\examples\matlab_featured to C:\Program Files\MATLAB\R2016b.

cd ..\..

Use a relative path to change the current folder from C:\Program Files\MATLAB\R2016b back to C:\Program Files\MATLAB\R2016b\examples\matlab_featured.

cd examples\matlab_featured

Change the current folder to a new location, then restore the current folder to its original location.

Change the current folder to the featured examples folder for MATLAB® R2016b, assuming that version is installed on your C: drive.

cd 'C:\Program Files\MATLAB\R2016b\examples\matlab_featured'

Change the current folder to C:\Program Files, saving the folder path before changing it.

oldFolder = cd('C:\Program Files')
oldFolder =

'C:\Program Files\MATLAB\R2016b\examples\matlab_featured'

Use the cd command to display the new current folder.

cd
C:\Program Files

Change the current folder back to the original folder, using the stored path. Use the cd command to display the new current folder.

cd(oldFolder)
cd
C:\Program Files\MATLAB\R2016b\examples\matlab_featured

Change the current folder to the featured examples folder for MATLAB R2016b, assuming that version is installed in your user home folder on a UNIX platform.

cd ~/MATLAB/R2016b/examples/matlab_featured

## Input Arguments

collapse all

Folder path to which you want to change the current folder, specified as a character vector. Valid values include:

• A full or relative path.

• ../, which indicates up one level from the current folder.

• Multiples of ../, which indicates multiple levels up from the current folder.

• ./, which indicates a path relative to the current folder. cd assumes that the path is relative to the current folder even if the ./ is not present.

If newFolder contains spaces, enclose it in single quotation marks.

On UNIX® systems, you can use the ~ (tilde) character to represent the user home folder.

## Output Arguments

collapse all

The current folder that was in place before you issued the cd command, specified as a character vector.

collapse all

### Current Folder

The current folder is a reference location that MATLAB uses to find files. This folder is sometimes referred to as the current directory, current working folder, or present working directory.