Main Content

delete

Delete files or objects

Description

delete filename deletes filename from disk, without requesting verification.

By default, the specified file is permanently deleted. To change whether the file is permanently deleted or sent to the recycle folder, go to the Home tab, and in the Environment section, click Preferences. Select MATLAB > General and in the Deleting files section, select from the available options. Alternatively, you can use the recycle function.

When file recycling is on, the delete function moves deleted files to a location specific to the platform:

  • Windows® — Recycle bin

  • macOS — Trash

  • Linux® platforms — Subfolder with the prefix MATLAB_Files_ in the system temporary folder, as returned by the tempdir function

Note

On macOS, file recycling is not applied to files deleted from network drives.

example

delete filename1 ... filenameN deletes the specified files from disk.

delete(filename,ResolveSymbolicLinks=tf) specifies whether to delete a symbolic link or remove the target of the symbolic link. (since R2024b)

delete(obj) deletes the specified object. If obj is an array, then delete deletes all objects in the array. obj remains in the workspace, but is no longer valid.

example

Examples

collapse all

Delete all files in the current folder with a .mat extension.

delete *.mat

Delete a graphics object and a graphics object array.

Create a bar chart and plot five lines. Then delete the bar chart.

b = bar(1:5);
hold on
P = plot(magic(5));
delete(b)

Figure contains an axes object. The axes object contains 5 objects of type line.

The Bar object variable b remains in the workspace, but no longer refers to an object.

display(b)
b = 
  handle to deleted Bar

Delete all the Line objects created by plot.

delete(P)

Figure contains an axes object. The axes object is empty.

Input Arguments

collapse all

Name of file to delete, specified as a character vector or string scalar. filename can be an absolute or relative path and can include wildcards (*). To delete files from a remote location, filename must contain a full path specified as a uniform resource locator (URL). For more information, see Work with Remote Data.

Object to delete, specified as a single object or an array of objects.

Since R2024b

Remove the target of the symbolic link, specified as a numeric or logical 0 (false) or 1 (true). If tf is false, delete deletes the symbolic link. If tf is true, delete removes the target of the symbolic link. If the target of the symbolic link is a folder, it must be empty to be deleted.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced before R2006a

expand all