How to find reason for failed RenameFile()?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

How to find reason for failed RenameFile()?

Post by Kukulkan »

Hi,

I want to move files using RenameFile() from network share with virus scanner to local share. If the virus scanner catches the file, I want to know it (to give user information). But RenameFile() is only saying Yes or No.

But there are many possible reasons for failure. I need to know if it has been because of:
- ERROR_FILE_NOT_FOUND
- ERROR_ACCESS_DENIED
- ERROR_INVALID_DRIVE
- ERROR_NOT_READY
- ERROR_READ_FAULT
- ERROR_VIRUS_INFECTED
- ERROR_VIRUS_DELETED

Any idea how to get this return codes without the need to use API (cross plattform)? Something like GetLastIOError() function?

Kukulkan
MicroByte
New User
New User
Posts: 8
Joined: Tue May 08, 2012 11:06 pm

Re: How to find reason for failed RenameFile()?

Post by MicroByte »

You can use the API function "GetLastError" with PB functions as they call the API (on windows), but i would use "MoveFile" if using API error checking .... just in case!!

Code: Select all

;result = RenameFile("||.ext", "nofile2.ext")
result = MoveFile_("||.ext", "nofile2.ext")

Buffer.s = Space(4096)
Chars.l = FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError_(), 0, Buffer, Len(Buffer), 0)
Debug Left(Buffer, Chars-2)
that would take care of the windows part, cant help for other OS's, soz
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: How to find reason for failed RenameFile()?

Post by Kukulkan »

Thanks MicroByte. Yes, that might work on Windows. MoveFile API is possibly the best solution.

But what is the return value of PB good for? Wouldn't it be much better to return some generalized errors? Maybe the most common ones in a PB specific way?

Anyway, I'd be happy to find the equivalents of Move_ on Linux and Mac...

Best

Kukulkan
Post Reply