-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeletewithsemaphores.m
More file actions
39 lines (35 loc) · 963 Bytes
/
deletewithsemaphores.m
File metadata and controls
39 lines (35 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function deletewithsemaphores(fileList)
%DELETEWITHSEMAPHORES Delete files using semaphors.
% DELETEWITHSEMAPHORES(FILELIST) deletes the files in cell array FILELIST
% using semaphores.
%
% Example:
% fileList = {'test1.txt', 'text2.txt'};
% deletewithsemaphores(fileList);
%
% Markus Buehren
% Last modified 05.04.2009
%
% See also SETFILESEMAPHORE, REMOVEFILESEMAPHORE.
import multicore.*
checkWaitTime = 0.1;
nrOfAttempts = 10;
showWarnings = 0;
if ischar(fileList)
fileList = {fileList};
end
for fileNr = 1:length(fileList)
sem = setfilesemaphore(fileList{fileNr});
for attemptNr = 1:nrOfAttempts
throwError = 0;
showWarningsNow = showWarnings && (attemptNr == nrOfAttempts); % only in last attempt
if mbdelete(fileList{fileNr}, showWarningsNow, throwError)
% deleting was successful
break
else
% wait some time and check again
pause(checkWaitTime);
end
end
removefilesemaphore(sem);
end