这是一个修改文件属性的API
使用下面WINDOWS API函数
- function SetFileAttributes(lpFileName: PChar; dwFileAttributes: DWORD): BOOL; stdcall;
- {$EXTERNALSYM SetFileAttributes}
- function SetFileAttributesA(lpFileName: PAnsiChar; dwFileAttributes: DWORD): BOOL; stdcall;
- {$EXTERNALSYM SetFileAttributesA}
- function SetFileAttributesW(lpFileName: PWideChar; dwFileAttributes: DWORD): BOOL; stdcall;
- {$EXTERNALSYM SetFileAttributesW}
function SetFileAttributes(lpFileName: PChar; dwFileAttributes: DWORD): BOOL; stdcall; {$EXTERNALSYM SetFileAttributes} function SetFileAttributesA(lpFileName: PAnsiChar; dwFileAttributes: DWORD): BOOL; stdcall; {$EXTERNALSYM SetFileAttributesA} function SetFileAttributesW(lpFileName: PWideChar; dwFileAttributes: DWORD): BOOL; stdcall; {$EXTERNALSYM SetFileAttributesW}
实例:
SetFileAttributes(
'
C:\test.exe
'
,FILE_ATTRIBUTE_HIDDEN
+
FILE_ATTRIBUTE_SYSTEM);
下面是文件属性,对应dwFileAttributes
- FILE_ATTRIBUTE_READONLY = $00000001;
- {$EXTERNALSYM FILE_ATTRIBUTE_READONLY}
- FILE_ATTRIBUTE_HIDDEN = $00000002;
- {$EXTERNALSYM FILE_ATTRIBUTE_HIDDEN}
- FILE_ATTRIBUTE_SYSTEM = $00000004;
- {$EXTERNALSYM FILE_ATTRIBUTE_SYSTEM}
- FILE_ATTRIBUTE_DIRECTORY = $00000010;
- {$EXTERNALSYM FILE_ATTRIBUTE_DIRECTORY}
- FILE_ATTRIBUTE_ARCHIVE = $00000020;
- {$EXTERNALSYM FILE_ATTRIBUTE_ARCHIVE}
- FILE_ATTRIBUTE_NORMAL = $00000080;
- {$EXTERNALSYM FILE_ATTRIBUTE_NORMAL}
- FILE_ATTRIBUTE_TEMPORARY = $00000100;
- {$EXTERNALSYM FILE_ATTRIBUTE_TEMPORARY}
- FILE_ATTRIBUTE_COMPRESSED = $00000800;
- {$EXTERNALSYM FILE_ATTRIBUTE_COMPRESSED}
- FILE_ATTRIBUTE_OFFLINE = $00001000;