move folders to another drive lazarus / 21-General ---------------------------------------------------------------------- Ericktux · 2022-11-20 16:30 hello brothers, i am looking for the simplest way to move folders to another drive, the "renamefile" function is simple and cross-platform, but it only moves folders in the same drive, for other drives it cannot move. opening as admin doesn't work either  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  Form1: TForm1;  origen_1, destino_1 : string;   .... procedure TForm1.Button1Click(Sender: TObject);begin  origen_1:='D:\test\casa\';  destino_1:='C:\test\trabajo\casa\';  //destino_1:='F:\test\trabajo\casa\'; // doesn't work either  if RenameFile(origen_1,destino_1) then  begin  ShowMessage('yes');  end   else     begin     ShowMessage('not');     end;end; PD: I am using win10x64 + lazarusx86 ---------------------------------------------------------------------- Bart · 2022-11-20 16:47 I'm afraid you'll have to copy and then delete... Bart ---------------------------------------------------------------------- KodeZwerg · 2022-11-20 18:01 Quote from: Ericktux on November 20, 2022, 05:30:49 pmPD: I am using win10x64 + lazarusx86 https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf- winbase-movefile This works very well for me on Windows for files or folders. If you need an example exclusive for Windows I can write you one. ---------------------------------------------------------------------- PascalDragon · 2022-11-20 21:49 Quote from: Ericktux on November 20, 2022, 05:30:49 pmhello brothers, i am looking for the simplest way to move folders to another drive, the "renamefile" function is simple and cross-platform, but it only moves folders in the same drive, for other drives it cannot move. opening as admin doesn't work either  You need to do a copy-and-delete. That's how it works on any operating system and that's what a function like WinAPI's MoveFile that was suggested by KodeZwerg does as well. So you can just as well develop it yourself (or there might already be cross platform functions for that) and then you'll be cross platform anyway. ---------------------------------------------------------------------- Ericktux · 2022-11-21 02:37 Hello friends, I just tried with movefile and it doesn't move to another unit either, not as admin either, could it be that Windows 10 works differently? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  origen_1:='D:\test\casa';  destino_1:='C:\test\trabajo\casa';  //if RenameFile(origen_1,destino_1) then if moveFile(pchar(origen_1),pchar(destino_1)) then  ShowMessage('yes')   else     ShowMessage('not');end; ---------------------------------------------------------------------- KodeZwerg · 2022-11-21 03:30 Quote from: Ericktux on November 21, 2022, 03:37:47 amHello friends, I just tried with movefile and it doesn't move to another unit either, not as admin either, could it be that Windows 10 works differently?1. You do not need to run such as admin, only when source or destination is protected. 2. I show you my own implementation that worked for me. 3. Copy and Delete is as suggested the better way for x-Platform etc. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf- winbase-movefilefunction MoveFileW(lpExistingFileName, lpNewFileName: PWideChar): BOOL; stdcall; external 'Kernel32.dll' name 'MoveFileW'; procedure TForm1.Button1Click(Sender: TObject);var  Src, Dst: WideString;begin  Src := 'C:\Test\FileOrg.txt';  Dst := 'D:\Test\FileNew.txt';  if ForceDirectories(ExtractFilePath(Dst)) then    begin      if (not MoveFileW(PWideChar(Src), PWideChar(Dst))) then        ShowMessage(Src + ' -> ' + Dst + ' failed to move.');    end    else      ShowMessage(ExtractFilePath(Dst) + ' folder creation error.'); Happy testing. ---------------------------------------------------------------------- Ericktux · 2022-11-21 04:02 thank you very much friend for your help, i just tried and it works with files but not with folders, still the same error, can't move folders to another drive ---------------------------------------------------------------------- KodeZwerg · 2022-11-21 05:24 Quote from: Ericktux on November 21, 2022, 05:02:48 amthank you very much friend for your help, i just tried and it works with files but not with folders, still the same error, can't move folders to another drive  I am sorry, it was my fault, I didnt fully read the Microsoft remarks! QuoteThe one caveat is that the MoveFile function will fail on directory moves when the destination is on a different volume.So here is a working Folder move, including sub-folder etc... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TSHFileOpStruct = record    Wnd: HWND;    wFunc: UINT;    pFrom: LPCWSTR;    pTo: LPCWSTR;    fFlags: FILEOP_FLAGS;    fAnyOperationsAborted: BOOL;    hNameMappings: Pointer;    lpszProgressTitle: LPCWSTR;  end; const  FO_MOVE = $0001;  FOF_NOCONFIRMMKDIR = $0200; function SHFileOperationW(const lpFileOp: TSHFileOpStruct): Integer; stdcall; external 'shell32.dll' name 'SHFileOperationW'; function MoveDir(SrcDir, DstDir: WideString): Boolean;var  FOS: TSHFileOpStruct;begin  ZeroMemory(@FOS, SizeOf(FOS));  FOS.Wnd := Application.Handle;  FOS.wFunc := FO_MOVE;  FOS.fFlags := FOF_NOCONFIRMMKDIR;  FOS.pFrom := PWideChar(IncludeTrailingPathDelimiter(SrcDir) + '*.*'#0);  FOS.pTo := PWideChar(DstDir + #0);  Result := (SHFileOperationW(FOS) = 0);end; procedure TForm1.Button1Click(Sender: TObject);var  Src, Dst: WideString;begin  Src := 'C:\Test';  Dst := 'D:\Test';  if (not MoveDir(Src, Dst)) then    ShowMessage(Src + ' -> ' + Dst + ' failed to move.')    else    if (not RemoveDir(Src)) then      ShowMessage('Unable to remove ' + Src);end;Happy testing. (and please do not use my above stuff by checking for true as result, only work with false checking like i showed!) ---------------------------------------------------------------------- ASerge · 2022-11-21 15:05 Quote from: KodeZwerg on November 21, 2022, 04:30:33 amHappy testing. By the way, the RenameFile function internally uses the MoveFileW function in Windows. So the problem is most likely either in the permissions, or in the absence of a directory, or in the existence of the resulting file. ---------------------------------------------------------------------- KodeZwerg · 2022-11-21 15:59 Quote from: ASerge on November 21, 2022, 04:05:04 pmQuote from: KodeZwerg on November 21, 2022, 04:30:33 amHappy testing. By the way, the RenameFile function internally uses the MoveFileW function in Windows. So the problem is most likely either in the permissions, or in the absence of a directory, or in the existence of the resulting file. Or in the remark from Microsoft what I have quoted above that MoveFile does not work when moving folders to other volumes. ---------------------------------------------------------------------- Ericktux · 2022-11-21 16:50 hello friend now it works, but when i use it with files these files are created as folders...  I see that there is no simple way  , no way I will continue trying, I think I have a similar code I will look for it ---------------------------------------------------------------------- KodeZwerg · 2022-11-21 17:08 Quote from: Ericktux on November 21, 2022, 05:50:53 pmhello friend now it works, but when i use it with files these files are created as folders...  I see that there is no simple way  , no way I will continue trying, I think I have a similar code I will look for it You got a windows solution from me for files. You got a windows solution from me for folders. What you need more? ---------------------------------------------------------------------- Bart · 2022-11-21 17:23 How difficult can it be to simply iterate the files in source, copy to dest, delete after succesfull copy (delete target if copy partially fails)? And if that is too difficult, you can always use ShellExcute() to launch move.exe with appropriate paramters. ---------------------------------------------------------------------- KodeZwerg · 2022-11-21 18:46 Quote from: Ericktux on November 21, 2022, 05:50:53 pmhello friend now it works, but when i use it with files these files are created as folders...  I see that there is no simple way  , no way I will continue trying, I think I have a similar code I will look for it If you have no idea how to solve, that works aslong you keep mechanism to my above examples. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if FileExists(Src) then    begin      if ForceDirectories(ExtractFilePath(Dst)) then        begin          if (not MoveFileW(PWideChar(Src), PWideChar(Dst))) then            ShowMessage(Src + ' -> ' + Dst + ' failed to move.');        end      else          ShowMessage(ExtractFilePath(Dst) + ' folder creation error.');    end;  if DirectoryExists(Src) then    begin      if (not MoveDir(Src, Dst)) then          ShowMessage(Src + ' -> ' + Dst + ' failed to move.')          else          if (not RemoveDir(Src)) then            ShowMessage('Unable to remove ' + Src);    end; ---------------------------------------------------------------------- Ericktux · 2022-11-22 01:13 Quote from: KodeZwerg on November 21, 2022, 07:46:09 pmQuote from: Ericktux on November 21, 2022, 05:50:53 pmhello friend now it works, but when i use it with files these files are created as folders...  I see that there is no simple way  , no way I will continue trying, I think I have a similar code I will look for it If you have no idea how to solve, that works aslong you keep mechanism to my above examples. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if FileExists(Src) then    begin      if ForceDirectories(ExtractFilePath(Dst)) then        begin          if (not MoveFileW(PWideChar(Src), PWideChar(Dst))) then            ShowMessage(Src + ' -> ' + Dst + ' failed to move.');        end      else          ShowMessage(ExtractFilePath(Dst) + ' folder creation error.');    end;  if DirectoryExists(Src) then    begin      if (not MoveDir(Src, Dst)) then          ShowMessage(Src + ' -> ' + Dst + ' failed to move.')          else          if (not RemoveDir(Src)) then            ShowMessage('Unable to remove ' + Src);    end; Thank you very much friend, now it works for files and folders  , just one last question: where can i put showmessage('successful operation') ---------------------------------------------------------------------- KodeZwerg · 2022-11-22 03:16 Quote from: Ericktux on November 22, 2022, 02:13:07 amwhere can i put showmessage('successful operation')  I simplified it for you so you can tell "success" or "failed". When you want more of the "failed" messages, stick to old code and add some "else" wherever you need it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function MoveFileW(lpExistingFileName, lpNewFileName: PWideChar): BOOL; stdcall; external 'Kernel32.dll' name 'MoveFileW'; type  TSHFileOpStructW = record    Wnd: HWND;    wFunc: UINT;    pFrom: LPCWSTR;    pTo: LPCWSTR;    fFlags: FILEOP_FLAGS;    fAnyOperationsAborted: BOOL;    hNameMappings: Pointer;    lpszProgressTitle: LPCWSTR;  end; const  FO_MOVE = $0001;  FOF_NOCONFIRMMKDIR = $0200; function SHFileOperationW(const lpFileOp: TSHFileOpStructW): Integer; stdcall; external 'shell32.dll' name 'SHFileOperationW'; function MoveDir(const Src, Dst: WideString): Boolean;var  FOS: TSHFileOpStructW;begin  ZeroMemory(@FOS, SizeOf(FOS));  FOS.Wnd := Application.Handle;  FOS.wFunc := FO_MOVE;  FOS.fFlags := FOF_NOCONFIRMMKDIR;  FOS.pFrom := PWideChar(IncludeTrailingPathDelimiter(Src) + '*.*'#0);  FOS.pTo := PWideChar(Dst + #0);  Result := (SHFileOperationW(FOS) = 0);end; // this method wants either a full source and destination path// or a full source and destination path with "filename.ext"// it return true on success or false on failurefunction MoveData(const Src, Dst: WideString): Boolean;begin  Result := False;  if FileExists(Src) then    begin      Result := ForceDirectories(ExtractFilePath(Dst));      if Result then        Result := MoveFileW(PWideChar(Src), PWideChar(Dst));    end  else // file did not exists, try folder operation  if DirectoryExists(Src) then    begin      Result := MoveDir(Src, Dst);      if Result then        Result := RemoveDir(Src);    end;end; procedure TForm1.Button1Click(Sender: TObject);var  Src, Dst: WideString;begin  Src := 'C:\Test';  Dst := 'D:\Test';  if MoveData(Src, Dst) then    ShowMessage('All Good.')    else    ShowMessage('Not successful.');end;Quote from: Ericktux on November 22, 2022, 02:13:07 amThank you very much friend You are welcome ---------------------------------------------------------------------- Ericktux · 2022-11-22 04:55 Hello friend, thank you very much, very kind, I have copied the code as it is and I get this error: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function MoveDir(const Src, Dst: WideString): Boolean;var  FOS: TSHFileOpStructW;begin  ZeroMemory(@FOS, SizeOf(FOS));  FOS.Wnd := Application.Handle;  FOS.wFunc := FO_MOVE;  FOS.fFlags := FOF_NOCONFIRMMKDIR;  FOS.pFrom := PWideChar(IncludeTrailingPathDelimiter(Src) + '*.*'#0);  FOS.pTo := PWideChar(Dst + #0);  Result := (SHFileOperationW(FOS) = 0);  // here mark error in "FOS"end;   in the message window it shows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit1.pas(66,34) Error: Incompatible type for arg no. 1: Got "TSHFileOpStructW", expected "_SHFILEOPSTRUCTA" ---------------------------------------------------------------------- KodeZwerg · 2022-11-22 05:03 Quote from: Ericktux on November 22, 2022, 05:55:12 amI have copied the code as it is and I get this error You need to copy and paste everything from my last again. The older is not compatible, I changed source. ---------------------------------------------------------------------- KodeZwerg · 2022-11-22 14:09 If you still got errors, in attachment is a unit, just include it in your uses like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ....FileHelper...and call it like i showed on last post: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  Src, Dst: WideString;begin  Src := 'C:\Test';  Dst := 'D:\Test';  if FileHelper.MoveData(Src, Dst) then // i added unit name infront of method to ensure that my method is called.    ShowMessage('All Good.')    else    ShowMessage('Not successful.');end;I hope now all works fluffy for you. ---------------------------------------------------------------------- Ericktux · 2022-11-22 14:55 Thank you very much friend, now everything works perfect.  Excuse me if I abuse your courtesy, I have a question, if one day I have files or folders with long names, will this code work ?? Thanks for your time. ---------------------------------------------------------------------- KodeZwerg · 2022-11-22 15:01 My method is limited to a max name length of 32767 (wide)-chars. Is that long enough? ---------------------------------------------------------------------- Ericktux · 2022-11-22 15:03 wow thank you very much friend. ---------------------------------------------------------------------- KodeZwerg · 2022-11-22 15:15 Sorry, you need to update the filehelper.pas file to enable to long path setting. Change this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           Result := MoveFileW(PWideChar(Src), PWideChar(Dst));into that Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           Result := MoveFileW(PWideChar('\\?\' + Src), PWideChar('\\?\' + Dst));and now you got 32k for files. edit: Sorry, for folders this does not apply, I never tested anything beyond MAX_PATH length. As far as I understand the WinAPI it is not possible with my method to use folders longer than MAX_PATH. ---------------------------------------------------------------------- Ericktux · 2022-11-22 16:03 I understand my friend, don't worry, it's not urgent, rather I have a question, the code you gave me works perfect for folders, in the case of files, if it already exists, it doesn't overwrite it, I've read that I should use copyfile and then deletefile to be able to overwrite it, I'll do some tests and tell you ---------------------------------------------------------------------- KodeZwerg · 2022-11-22 16:33 Quote from: Ericktux on November 22, 2022, 05:03:57 pmI understand my friend, don't worry, it's not urgent, rather I have a question, the code you gave me works perfect for folders, in the case of files, if it already exists, it doesn't overwrite it, I've read that I should use copyfile and then deletefile to be able to overwrite it, I'll do some tests and tell you Re-Uploaded, fixed small issue. Now it will overwrite per default even hidden, readonly etc.. files. Call it like this to overwrite files Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if FileHelper.MoveData(Src, Dst) then Call it like this to skip moving existing files Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if FileHelper.MoveData(Src, Dst, False) then I hope now all is okay. Re-ReUploaded.... forgot to tweak the deletefile operation. ---------------------------------------------------------------------- Ericktux · 2022-11-22 16:43 Thank you very much friend, one question, what would be better to overwrite? first delete destination file (if it exists) and then move source file. or first copy file overwriting old file, and then delete source file ---------------------------------------------------------------------- KodeZwerg · 2022-11-22 17:00 Quote from: Ericktux on November 22, 2022, 05:43:11 pmThank you very much friend, one question, what would be better to overwrite? first delete destination file (if it exists) and then move source file. or first copy file overwriting old file, and then delete source file I do not really understand the question. If you want to overwrite just call my method without using 3rd parameter and it does do all automagical for you. When you plan to create your own way of doing with overwrite ability than this would be the correct order: 1. check if destination exists 2. if 1. is true than set the file attribute to be able to delete 3. if 1. and 2. is true than delete the file 4. if 2. and 3. is true or 1. was false than copy the file 5. if 4. is true than do the same 2. and 3. for the source file ---------------------------------------------------------------------- Ericktux · 2022-11-22 22:08 ok friend, thank you very much for helping me ---------------------------------------------------------------------- Ericktux · 2022-12-01 00:46 Hello brothers, I just made a modification to the code to be able to copy files and folders, that's how I'm using it at the moment and it works fine  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, FileHelper; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1;  Src, Dst: WideString;   const    FO_MOVE   = $0001;    FO_COPY   = $0002; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); // FOR MOVEbegin  if FileHelper.MoveData(Src, Dst, FO_MOVE) then // i added unit name infront of method to ensure that my method is called.     ShowMessage('All Good.')     else     ShowMessage('Not successful.'); end; procedure TForm1.Button2Click(Sender: TObject); // FOR COPYbegin  if FileHelper.MoveData(Src, Dst, FO_COPY) then // i added unit name infront of method to ensure that my method is called.     ShowMessage('All Good.')     else     ShowMessage('Not successful.');end; procedure TForm1.FormCreate(Sender: TObject);begin  Src := 'D:\test\casa\jaja.txt';  Dst := 'C:\test\trabajo\jaja.txt';  {  Src := 'D:\test\casa\';  Dst := 'C:\test\trabajo\casa\';  }end; end. also modify the "filehelper.pas" unit of the friend KodeZwerg Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit FileHelper; {$mode ObjFPC}{$H+} interface uses  Windows, SysUtils; function MoveData(const Src, Dst: WideString; Func: Integer; FileOverwrite: Boolean = True): Boolean; implementation   const    {FO_MOVE   = $0001;    FO_COPY   = $0002;    FO_DELETE = $0003;    FO_RENAME = $0004;}    FOF_NOCONFIRMMKDIR = $0200;    FOF_NOCONFIRMATION = $0010;    { Don't prompt the user. }    FOF_SIMPLEPROGRESS = $0100;    { means don't show names of files }    FOF_SILENT         = $0004;    { don't create progress/report }   type    TSHFileOpStructW = record      Wnd: HWND;      wFunc: UINT;    pFrom: LPCWSTR;      pTo: LPCWSTR;      fFlags: FILEOP_FLAGS;      fAnyOperationsAborted: BOOL;      hNameMappings: Pointer;      lpszProgressTitle: LPCWSTR;    end;   function MoveFileW(lpExistingFileName, lpNewFileName: PWideChar): BOOL; stdcall; external 'Kernel32.dll' name 'MoveFileW';  function CopyFileW(lpExistingFileName, lpNewFileName: PWideChar; bFailIfExists: BOOL): BOOL; stdcall; external 'Kernel32.dll' name 'CopyFileW';   {  function CopyFileW(lpExistingFileName:LPCWSTR; lpNewFileName:LPCWSTR; bFailIfExists:WINBOOL):WINBOOL; external 'kernel32' name 'CopyFileW';  function MoveFileW(lpExistingFileName:LPCWSTR; lpNewFileName:LPCWSTR):WINBOOL; external 'kernel32' name 'MoveFileW';  }   function SHFileOperationW(const lpFileOp: TSHFileOpStructW): Integer; stdcall; external 'shell32.dll' name 'SHFileOperationW';   function MoveDir(const Src, Dst: WideString; Func: Integer): Boolean;  var    FOS: TSHFileOpStructW;  begin    ZeroMemory(@FOS, SizeOf(FOS));    FOS.wFunc := Func; // FO_MOVE , FO_COPY;    FOS.fFlags := FOF_NOCONFIRMMKDIR or FOF_SIMPLEPROGRESS or FOF_NOCONFIRMATION or FOF_SILENT;    FOS.pFrom := PWideChar(IncludeTrailingPathDelimiter(Src) + '*.*'#0);    FOS.pTo := PWideChar(Dst + #0);    Result := (SHFileOperationW(FOS) = 0);  end;   // this method wants either a full source and destination path  // or a full source and destination path with "filename.ext"  // it return true on success or false on failure  function MoveData(const Src, Dst: WideString; Func: Integer; FileOverwrite: Boolean = True): Boolean;  begin    Result := False;    if FileExists(Src) then      begin      Result := ForceDirectories(ExtractFilePath(Dst));        if Result then          begin            if (FileOverwrite and FileExists(Dst)) then              Result := ((SetFileAttributesW(PWideChar('\\?\' + Dst), faNormal)) and DeleteFileW(PWideChar('\\?\' + Dst)));          if Result then               begin                    if Func = $0001 then Result := MoveFileW(PWideChar('\\?\' + Src), PWideChar('\\?\' + Dst));  // move                    if Func = $0002 then Result := CopyFileW(PWideChar('\\?\' + Src), PWideChar('\\?\' + Dst), false);  // copy               end;           end;      end    else    if DirectoryExists(Src) then      begin        Result := MoveDir(Src, Dst, Func);        if Result then          begin            if Func = $0001 then Result := RemoveDir(Src); // only remove empty folder when using FO_MOVE            //Result := RemoveDir(Src);          end;    end;  end; end. At the moment it works fine, but if I'm doing something wrong please correct me  PD: I attached the project. ---------------------------------------------------------------------- KodeZwerg · 2022-12-01 08:29 Quote from: Ericktux on December 01, 2022, 01:46:41 amAt the moment it works fine, but if I'm doing something wrong please correct me  Just a minor thing I would do different, when you having your "Func" like FO_COPY, use it also in code and not the binary part. I would write this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           if Result then               begin                    if Func = $0001 then Result := MoveFileW(PWideChar('\\?\' + Src), PWideChar('\\?\' + Dst));  // move                    if Func = $0002 then Result := CopyFileW(PWideChar('\\?\' + Src), PWideChar('\\?\' + Dst), false);  // copy               end;In a way like that Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           if Result then               case Func of                 FO_MOVE: Result := MoveFileW(PWideChar('\\?\' + Src), PWideChar('\\?\' + Dst));  // move                 FO_COPY: Result := CopyFileW(PWideChar('\\?\' + Src), PWideChar('\\?\' + Dst), false);  // copy                 else                   Result := False;               end;