Forum > General
move folders to another drive
Ericktux:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
I'm afraid you'll have to copy and then delete...
Bart
KodeZwerg:
--- Quote from: Ericktux on November 20, 2022, 05:30:49 pm ---PD: I am using win10x64 + lazarusx86
--- End quote ---
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:
--- Quote from: Ericktux on November 20, 2022, 05:30:49 pm ---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 :(
--- End quote ---
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:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;
Navigation
[0] Message Index
[#] Next page