Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I cannot do a filecopy in Delhi, getting conflicting error codes

Steve_again

Programmer
Sep 22, 2023
3
US
I am trying to use Delphi to copy a .txt file to an external usb hard drive.

Depending on how I code it, I get 2 different error codes: error 80 (Destination File is there) and Error 32 file not found.
The code is: copyfile(pchar(mysrc),pchar(mydest),b1);

I use an "if file exists(mysrc) and it shows it is there.
The error 32 tells me the copy of the file needs to be there, so it has something to overwrite.
So I renamed another file to have the same file name as the source file. It fails on an error 80, the Dest file is there.

I though that even though the source file is there, I suspected it might be related to permissions. I went into folder properties, set it the share, and gave user "Everyone full control, but it still says file not found. Which file, the is not found - source or destination?

Thanks in advance, people.
- Steve
 
try some like this:

Drives: DWORD;
DriveType: UINT;

Drives := GetLogicalDrives; API MSWindows

if (Drives and (1 shl (Ord(DriveLetter) - Ord('A'))) <> 0) then
....
DriveType := GetDriveType(PChar(DriveLetter + ':\')); try a looping of letter a..z
if DriveType = DRIVE_REMOVABLE then ....

if CopyFile(PChar(Origem), PChar(Destino), False) then
ShowMessage('Arquivo copia!');

if GetLastError() ....
end;
 
try some like this:

Drives: DWORD;
DriveType: UINT;

Drives := GetLogicalDrives; API MSWindows

if (Drives and (1 shl (Ord(DriveLetter) - Ord('A'))) <> 0) then
....
DriveType := GetDriveType(PChar(DriveLetter + ':\')); try a looping of letter a..z
if DriveType = DRIVE_REMOVABLE then ....

if CopyFile(PChar(Origem), PChar(Destino), False) then
ShowMessage('Arquivo copia!');

if GetLastError() ....
end;
Thank you for your reply. It works! I had a few lines that did not compile: a comment line,
the variable drive letter was not found, but I hard-coded where needed and it worked.
I looked closely to see what was different from my original non-working program and they were vary similar.
I ran my original non-working program and it worked.

I can only guess it was either caused by a Win10 update or caused by the Macrium trial program I installed.
 

Part and Inventory Search

Sponsor

Back
Top