WinAPI: CreateDirectory - 建立文件夹
//声明:
CreateDirectory(
lpPathName: PChar; {目录名}
lpSecurityAttributes: PSecurityAttributes {TSecurityAttributes 结构的指针}
): BOOL;
//TSecurityAttributes 是 _SECURITY_ATTRIBUTES 结构的重定义
_SECURITY_ATTRIBUTES = record
nLength: DWORD; {结构体的大小}
lpSecurityDescriptor: Pointer; {安全描述}
bInheritHandle: BOOL; {安全描述的对象能否被新创建的进程继承}
end;
//举例:
var
dir: string;
begin
dir := 'c:\temp\TestDir';
CreateDirectory(PChar(dir), nil); {第二个参数一般设为 nil, 表示使用系统默认的安全属性}
end;
WinAPI: CreateDirectoryEx - 根据模版建立文件夹
//声明:
CreateDirectoryEx (
lpTemplateDirectory: PChar; {模版目录名}
lpPathName: PChar; {新目录名}
lpSecurityAttributes: PSecurityAttributes {TSecurityAttributes 结构的指针}
): BOOL;
//TSecurityAttributes 是 _SECURITY_ATTRIBUTES 结构的重定义
_SECURITY_ATTRIBUTES = record
nLength: DWORD; {结构体的大小}
lpSecurityDescriptor: Pointer; {安全描述}
bInheritHandle: BOOL; {安全描述的对象能否被新创建的进程继承}
end;
//举例:
var
TDir,Dir: string;
begin
TDir := 'c:\temp\Test'; {假如模版目录是隐藏的}
Dir := 'c:\temp\NewDir'; {创建的新目录也是隐藏的}
CreateDirectoryEx(PChar(TDir), PChar(Dir), nil);
{如果不需要模版, 可以:}
//CreateDirectoryEx(nil, PChar(Dir), nil);
end;
WinAPI: RemoveDirectory - 删除空目录
//声明:
RemoveDirectory(
lpPathName: PAnsiChar {目录名}
): BOOL;
//举例:
var
Dir: string;
begin
Dir := 'c:\temp\Test';
if RemoveDirectory(PChar(Dir)) then
ShowMessage(Dir + ' 已被删除')
else
ShowMessage('删除失败, 可能是 ' + Dir + ' 不存在或不为空');
end;
WinAPI: SetCurrentDirectory、GetCurrentDirectory - 设置与获取当前目录
//声明:
SetCurrentDirectory(
lpPathName: PAnsiChar {路径名}
): BOOL;
GetCurrentDirectory(
nBufferLength: DWORD; {缓冲区大小}
lpBuffer: PAnsiChar {缓冲区}
): DWORD; {返回目录实际长度}
//举例:
var
buf: array[0..MAX_PATH] of Char;
begin
SetCurrentDirectory('c:\temp');
GetCurrentDirectory(SizeOf(buf), buf);
ShowMessage(buf); {c:\temp}
end;
WinAPI: SetVolumeLabel - 设置磁盘卷标
//声明:
SetVolumeLabel(
lpRootPathName: PChar; {根路径}
lpVolumeName: PChar {新卷标指针, nil 表示删除卷标}
): BOOL;
//举例:
begin
SetVolumeLabel('c:\', 'NewLabel');
end;