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 Settings. 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:
- 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.
delete [filename](#f71-847380-filename)1 ... [filename](#f71-847380-filename)N
deletes the specified files from disk.
delete(___,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.
Examples
Delete all files in the current folder with a .mat
extension.
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)
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
.
Input Arguments
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 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
Version History
Introduced before R2006a
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.
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.