0

That's what I want to achieve for my VCL application:

I extract a ZIP file to a directory in %TEMP%. If everything was okay, I move the directory to the target dir.

For the move operation I use JclFileUtils.FileMove (from JCL which resolves to MoveFileEx), because I need a real move operation and I want to overwrite files in the target dir.

This works so far, but the moved files have a per user file permission (inherited from Temp). I want the moved files to inherit permissions from the target folder.

Remarks:

  • Copy and delete is a workaround, I am aware of. But I want to avoid this (because of file size).
  • System.IOUtils.TFile.Move does not work for me, because it is implemented by copy and delete (in XE4).
  • Here a similar problem is described for .NET, but I do not know if an equivalent to GetAccessControl/SetAccessControl exists in Delphi.
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
yonojoy
  • 5,486
  • 1
  • 31
  • 60
  • 1
    This is expected behaviour if moving files within a volume. From [MS documentation](https://learn.microsoft.com/en-us/troubleshoot/windows-client/windows-security/permissions-on-copying-moving-files): _By default, an object inherits permissions from its parent object, either at the time of creation or when it is copied or moved to its parent folder. The only exception to this rule occurs when you move an object to a different folder on the same volume. In this case, the original permissions are retained._ – yonojoy Dec 30 '21 at 13:21
  • You could try to use [SetNamedSecurityInfo](https://learn.microsoft.com/en-gb/windows/win32/api/aclapi/nf-aclapi-setnamedsecurityinfoa?redirectedfrom=MSDN) with the `DACL_SECURITY_INFORMATION` flag to reset file security to inherit after MoveFile() operation. – Jeaninez - MSFT Dec 31 '21 at 02:44

0 Answers0