cd
Change current folder
Description
cd
displays the current folder.
cd
changes the current folder to
newFolder
newFolder
. Folder changes are global. Therefore, if you use
cd
within a function, the folder change persists after
MATLAB® finishes executing the function.
Examples
Change the current folder to the featured examples folder for MATLAB R2017a, assuming that version is installed on your C:
drive.
cd 'C:\Program Files\MATLAB\R2017a\examples\matlab_featured'
Using the full path, change the current folder from C:\Program Files\MATLAB\R2017a\examples\matlab_featured
to C:\Program Files\MATLAB\R2017a
.
cd ..\..
Use a relative path to change the current folder from C:\Program Files\MATLAB\R2017a
back to C:\Program Files\MATLAB\R2017a\examples\matlab_featured
.
cd examples\matlab_featured
Change the current folder to the featured examples folder for MATLAB R2017a, assuming that version is installed on your C:
drive. Then restore the current folder to its original location.
Change the current folder to the featured examples folder for MATLAB R2017a.
cd 'C:\Program Files\MATLAB\R2017a\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\R2017a\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\R2017a\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
New folder path to which you want to change the current folder, specified
as a character vector or string scalar. If newFolder
is a
string, enclose it in parentheses. For example,
cd("FolderName")
.
Valid values include a full or relative path or one of these values.
../ | One level up from the current folder. |
Multiples of ../ | Multiple levels up from the current folder. |
./ | 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. For example, cd 'Folder Name'
.
On UNIX® systems, you can use the ~ (tilde) character to represent the
user home folder. For example, ~/
or
~username/
.
MATLAB resolves folder path names containing '.
',
'..
', and symbolic links to their
target location before changing the current folder. For example, if you
specify c:\matlab\..\work
, MATLAB resolves the path name to c:\work
before
changing the current folder.
Output Arguments
Previous current folder that was in place before you issued the
cd
command, returned as a character vector.
More About
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.
Extended Capabilities
Usage notes and limitations:
Dynamic memory allocation must be enabled for code generation.
Code generation for
cd
with inputs is not supported.
Usage notes and limitations:
When used to display the current folder,
cd
supports thread-based environments.When used to change the current folder,
cd
does not support thread-based environments.
For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006aOn Windows machines, leading whitespace characters in the input path are no longer trimmed. Input paths containing leading whitespace characters cause an error to be thrown instead.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)