delete - Delete files or objects - MATLAB (original) (raw)

Syntax

Description

delete [filename](#f71-847380-filename) deletesfilename 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 theHome tab, and in the Environment section, click Preferences. Select > 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:

Note

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

example

delete [filename](#f71-847380-filename)1 ... [filename](#f71-847380-filename)N deletes the specified files from disk.

delete([filename](#f71-847380-filename),ResolveSymbolicLinks=[tf](#mw%5F5b772dbd-a426-4b57-8167-1077a1b02460)) specifies whether to delete a symbolic link or remove the target of the symbolic link. (since R2024b)

delete([obj](#f71-847380-h)) deletes the specified object. Ifobj 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 Files in Folder

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

Delete Graphics Objects

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.

b = handle to deleted Bar

Delete all the Line objects created by plot.

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

Input Arguments

collapse all

filename — Name of file to delete

character vector | string scalar

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.

obj — Object

single object | array of objects

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

false or 0 (default) | true or 1

Since R2024b

Remove the target of the symbolic link, specified as a numeric or logical0 (false) or 1 (true). If tf isfalse, 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

You can delete files and folders using symbolic links. When you specify a symbolic link as input, you can control whether to delete the symbolic link itself or remove its target.

R2020a: Wildcard expression *.* on UNIX platforms matches only files that have an extension

Starting in R2020a, on UNIX® platforms, the wildcard expression *.* no longer matches folders or files without an extension. In previous releases, the expression matches folders or files regardless of extension, including files without an extension. This change of behavior does not apply to Microsoft® Windows platforms.