Ver Mensaje Individual
  #6  
Antiguo 20-07-2007
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Reputación: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Vale. Buscando por "RenameFile" al cabo se ve que utiliza (en Windows) la función "MoveFile" del API de Win32. Podrías usar esta función (por cierto, yo no sé qué **** han cambiado en la Web de MSDN que no encuentro la documentación de la función "MoveFile"), digo, en lugar de "RenameFile".

Lo digo porque la función "MoveFile" te permitirá recurrir a la función "GetLastError" en caso de que algo marche mal. Es posible que con "RenameFile" también puedas recurrir a "GetLastError", pero, si te fijas en esta función, verás que únicamente existe por compatibilidad con Linux: en Windows se acaba usando "MoveFile".

En fin. Yo vería qué me ofrece "GetLastError", y usaría "MoveFile" en lugar de "RenameFile" si no tuviera pensado migrar a Linux mi programa.

Código Delphi [-]
ShowMessage( SysErrorMessage(GetLastError()) );

Por cierto, como no consigo enlazar con la ayuda de la función "MoveFile", la copio aquí (desde la ayuda que incluye Delphi 2007), por si sirve de algo:

Cita:
Empezado por MoveFile
MoveFile

The MoveFile function moves an existing file or a directory, including its children.

To specify how to move the file, use the MoveFileEx function.


BOOL MoveFile(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName
);

Parameters
lpExistingFileName
[in] Pointer to a null-terminated string that names an existing file or directory.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95: This string must not exceed MAX_PATH characters.
lpNewFileName
[in] Pointer to a null-terminated string that specifies the new name of a file or directory. The new name must not already exist. A new file may be on a different file system or drive. A new directory must be on the same drive.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95: This string must not exceed MAX_PATH characters.
Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The MoveFile function will move (rename) either a file or a directory (including its children) either in the same directory or across directories. The one caveat is that the MoveFile function will fail on directory moves when the destination is on a different volume.

If a file is moved across volumes, MoveFile does not move the security descriptor with the file. The file will be assigned the default security descriptor in the destination directory.

The MoveFile function coordinates its operation with the link tracking service, so link sources can be tracked as they are moved.

__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita