deletewithsemaphores.m

来自「This contribution provides functions for」· M 代码 · 共 35 行

M
35
字号
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 21.12.2008
%
%		See also SETFILESEMAPHORE, REMOVEFILESEMAPHORE.

checkWaitTime = 0.1;

if ischar(fileList)
	fileList = {fileList};
end

for fileNr = 1:length(fileList)
	sem = setfilesemaphore(fileList{fileNr});
	for attemptNr = 1:10
		try
			if existfile(fileList{fileNr})
				delete(fileList{fileNr}); %% file access %%
			end
			break
		catch
			pause(checkWaitTime);
		end
	end
	removefilesemaphore(sem);
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?