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%> "Failed to delete <desc> from the local disk. File may be protected."<br>
20%> If the input ``desc`` is empty ``[]`` or empty string ``""``, a default
21%> value ``"the requested file"`` for ``desc`` will be added to the template.<br>
22%> (**optional**. If missing, no warning will be displayed upon failure.)
23%>
24%> \return
25%> ``failed`` : The output scalar MATLAB logical that is ``true`` if and
26%> only if the deletion of the input file fails,
27%> otherwise, return ``false``.<br>
28%>
29%> \interface{rmfile}
30%> \code{.m}
31%>
32%> failed = pm.sys.path.rmfile(file)
33%> failed = pm.sys.path.rmfile(file, desc)
34%>
35%> \endcode
36%>
37%> \example{rmfile}
38%> \include{lineno} example/sys/path/rmfile/main.m
39%> \output{rmfile}
40%> \include{lineno} example/sys/path/rmfile/main.out.m
41%>
42%> \final{rmfile}
43%>
44%> \author
45%> \JoshuaOsborne, May 21 2024, 5:28 AM, University of Texas at Arlington<br>
46%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
47%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
48function failed = rmfile(file, desc)
49 try
50 delete(file);
51 catch me
52 if nargin == 2
53 if isempty(desc) || desc == ""
54 desc = "the requested file";
55 end
56 warning ( newline ...
57 + string(me.identifier) + " : " + string(me.message) + newline ...
58 + "Failed to delete " + string(desc) + " from the local disk." + newline ...
59 + "An application may possess the file ownership, particularly on Windows." + newline ...
60 + "You can try manually deleting it at:" + newline ...
61 + newline ...
62 + pm.io.tab + string(file) + newline ...
63 + newline ...
64 );
65 end
66 end
67 failed = isfile(file);
68end
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,...