gusucode.com > vnt工具箱matlab源码程序 > vnt/vntblks/vntmasks/private/privatevntslvalidatefile.m
function [success errMsg] = privatevntslvalidatefile(fileName, blockName) %PRIVATEVNTSLVALIDATEFILE Check if replay file exists during simulation. % % SUCCESS = PRIVATEVNTSLVALIDATEFILE (FILENAME, BLOCKNAME, VARARGIN) % Check if replay/log file exists during simulation. % For Replay - Check if file exists. % For Log - Check if the folder exists and is writable. % SS 03-01-11 % Copyright 2011 The MathWorks, Inc. % Set this initially. success = true; errMsg = []; switch lower(blockName) case 'replay' % Check if file exists. fileExists = length(dir(fileName)); if ~fileExists success = false; strings = privatevntslstring('errorstrings'); errMsg = sprintf(strings.ReplayMATFileNotFound, fileName); end return; case 'log' path = fileparts(fileName); [~, tempFolderName] = fileparts(tempname); if ~isempty(path) dirExists = exist(path, 'dir'); if (dirExists) writable = mkdir(fullfile(path, tempFolderName)); if writable % Delete the temp dir. rmdir(fullfile(path, tempFolderName)); return; end success = false; strings = privatevntslstring('errorstrings'); errMsg = sprintf(strings.LogDirNotWritable, path); return; else %Log Dir does not exist. success = false; strings = privatevntslstring('errorstrings'); errMsg = sprintf(strings.LogDirNotFound, path); end else writable = mkdir(tempFolderName); if writable % Delete the temp dir. rmdir(tempFolderName); return; end success = false; strings = privatevntslstring('errorstrings'); errMsg = sprintf(strings.LogDirNotWritable, path); end otherwise assert('vnt:vntblks:invalidBlock', 'Invalid block specified'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%