首页 > 代码库 > Delphi文件夹的操作

Delphi文件夹的操作

/// <remarks>
/// 重命名文件夹
/// </remarks>
function ReNameDirectort(SourceDirectort, DestinationDirectort: string): Boolean;
var
  pDirOperate: TSHFileOpStruct;
begin
  Result := False;
  if not DirectoryExists(SourceDirectort) then Exit;
  FillChar(pDirOperate, SizeOf(pDirOperate), 0);
  pDirOperate.Wnd := 0;
  pDirOperate.pFrom :=PChar(SourceDirectort + #0);
  pDirOperate.pTo := PChar(DestinationDirectort + #0);

 

  // FO_RENAME:重命名;FO_DELETE:删除文件夹(空文件夹和非空文件夹都可以)

  // FO_COPY:复制;FO_MOVE:剪切
  pDirOperate.wFunc := FO_RENAME;

  pDirOperate.fFlags := FOF_RENAMEONCOLLISION;
  Result := SHFileOperation(pDirOperate) = 0;
end;