rename

Rename a file or folder in the target computer disk drive

Description

example

rename(filesys_object,'old_name', 'new_name') renames a file or folder in the target computer disk drive. If the file is open or does not exist, the function displays an error message.

Note: The SimulinkRealTime.fileSystem object will be removed in a future release. See the release note for file system commands to use instead. These commands use the SimulinkRealTime.openFTP function and the functions for the MATLAB ftp object.

Examples

collapse all

Renames the file old_data.dat to new_data.dat in the current folder.

tg = slrt;
fsys = SimulinkRealTime.fileSystem(tg);
dir(fsys);
30/10/2015	17:29                  0	OLD_DATA  DAT

If old_data.dat is open, close it with fclose.

rename(fsys, 'old_data.dat','new_data.dat');
dir(fsys);
30/10/2015	17:29                  0	NEW_DATA  DAT

Renames the file C:\old_temp\old_data.dat to C:\old_temp\new_data.dat.

tg = slrt;
fsys = SimulinkRealTime.fileSystem(tg);
dir(fsys,'C:\old_temp');
30/10/2015	17:29                  0	OLD_DATA  DAT

If old_data.dat is open, close it with fclose.

rename(fsys, 'C:\old_temp\old_data.dat', ...
     'C:\old_temp\new_data.dat');
dir(fsys,'C:\old_temp');
30/10/2015	17:29                  0	NEW_DATA  DAT

Moves the file C:\old_temp\new_data.dat to C:\new_temp\new_data.dat by renaming the folder part of the path.

tg = slrt;
fsys = SimulinkRealTime.fileSystem(tg);
dir(fsys,'C:\old_temp');
30/10/2015	17:29                  0	NEW_DATA  DAT

If new_data.dat is open, close it with fclose. If C:\new_temp does not exist, create it by using mkdir.

rename(fsys, 'C:\old_temp\new_data.dat', ...
     'C:\new_temp\new_data.dat');
dir(fsys,'C:\new_temp');
30/10/2015	17:29                  0	NEW_DATA  DAT

Input Arguments

collapse all

File system object created by using the SimulinkRealTime.fileSystem creation function.

The file system object represents the target computer file system. You work with the target computer file system from the development computer by using file system methods.

Example: fsys

Data Types: struct

The old name of the file or folder can be a name relative to the current folder or a fully qualified path.

Example: 'old_data.dat', 'C:\old_temp\old_data.dat'

Data Types: char | string

The new name of the file or folder can be a name relative to the current folder or a fully qualified path. If you are moving a file to a different folder, the folder must exist.

Example: 'new_data.dat', 'C:\new_temp\new_data.dat'

Data Types: char | string

Introduced in R2016a