ansible 的常用模块中没有判定当文件存在或者不存在时,执行某个执行 使用下面方法能简单判定某个文件是否存在 --- - name: judge a file or dir is exits shell: ls /home/sfy ignore_errors: True register: result - shell: echo "file exit" when: result|succeeded - shell: echo "file not exit" w
判断方法: DirectoryInfo di = new DirectoryInfo(path); if ((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) //为隐藏的 同理可以判断目录是否为只读(ReadOnly)或者系统(System)等其他属性.
FUNCTION WritableDir(CONST Dir : STRING) : BOOLEAN; VAR FIL : FILE; N : STRING; I : Cardinal; BEGIN REPEAT N:=IncludeTrailingPathDelimiter(Dir); FOR I:= TO -LENGTH(N) DO N:=N+CHAR(RANDOM()+) UNTIL NOT FileExists(N); Result:=TRUE; TRY AssignFile(FIL,N