ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
rmfile.m
Go to the documentation of this file.
1%> \brief
2%> Return a scalar MATLAB logical that is ``true`` if and
3%> only if the deletion of the input file fails,
4%> otherwise, return ``false``.<br>
5%>
6%> \details
7%> This function is a simple wrapper around the MATLAB function ``delete()``.<br>
8%> It is primarily meant to bring consistency to messaging file deletions if they fail.<br>
9%> Such consistency is particularly required on Windows systems
10%> as the OS tends to lock file ownership to one application
11%> causing deletions to fail frequently.<br>
12%>
13%> \param[in] file : The input scalar MATLAB string,
14%> containing the file path to be deleted.<br>
15%> \param[in] desc : The input scalar MATLAB string, containing a descriptive message
16%> to be printed on the MATLAB command line if the deletion task fails.<br>
17%> The input ``desc``, if not empty, will be added to the following template
18%> before being displayed:<br>
19%> \code{.m}
20%> "Failed to delete <desc> from the local disk. File may be protected."<br>
21%> \endcode
22%> If the input ``desc`` is empty ``[]`` or empty string ``""``, a default
23%> value ``"the requested file"`` for ``desc`` will be added to the template.<br>
24%> (**optional**. If missing, no warning will be displayed upon failure.)
25%>
26%> \return
27%> ``failed`` : The output scalar MATLAB logical that is ``true`` if and
28%> only if the deletion of the input file fails,
29%> otherwise, return ``false``.<br>
30%>
31%> \interface{rmfile}
32%> \code{.m}
33%>
34%> failed = pm.sys.path.rmfile(file)
35%> failed = pm.sys.path.rmfile(file, desc)
36%>
37%> \endcode
38%>
39%> \example{rmfile}
40%> \include{lineno} example/sys/path/rmfile/main.m
41%> \output{rmfile}
42%> \include{lineno} example/sys/path/rmfile/main.out.m
43%>
44%> \final{rmfile}
45%>
46%> \author
47%> \JoshuaOsborne, May 21 2024, 5:28 AM, University of Texas at Arlington<br>
48%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
49%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
50function failed = rmfile(file, desc)
51 try
52 delete(file);
53 catch me
54 if nargin == 2
55 if isempty(desc) || desc == ""
56 desc = "the requested file";
57 end
58 warning ( newline ...
59 + string(me.identifier) + " : " + string(me.message) + newline ...
60 + "Failed to delete " + string(desc) + " from the local disk. File may be protected." + newline ...
61 + "An application may possess the file ownership, particularly on Windows." + newline ...
62 + "You can try manually deleting it at:" + newline ...
63 + newline ...
64 + pm.io.tab + string(file) + newline ...
65 + newline ...
66 );
67 end
68 end
69 failed = isfile(file);
70end
function rmfile(in file, in desc)
Return a scalar MATLAB logical that is true if and only if the deletion of the input file fails,...