close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Opened 20 years ago

Closed 18 years ago

Last modified 18 years ago

#238 closed enhancement (fixed)

FileRename

Reported by: sdelfresno Owned by: Víctor de Buen Remiro
Priority: normal Milestone:
Component: Math Version: head
Severity: minor Keywords:
Cc:

Description

Good morning, I send this bug not like an error, but like a proposal of
improvement of the function ' FileRename'. This tol function renames an existing
file and in case of error gives back FALSE and if not, Certain. When having to both
specify path complete in parameters text that takes, we can rename a file in the
same path or move a file from path to another one with same or different name.
Nevertheless, this function does not allow the option to maintain the file in path of
origin if the user wishes it, since it always crushes it of path of origin. This problem
would be solved introducing a parameter in the function that allows to choose if we
want to erase or to maintain the file in path of origin.
Also, when using the function ' FileRename', if in path of destiny a file with the
same name exists that the one that we want to put, ' FileRename' gives error
because a file in the destiny with the same name exists. My proposal of
improvement in this case is that ' FileRename' would have to ask the user if he
wishes to replace it or not, and do what corresponds depending on the option
chosen by the user.
I have programmed all these improvements in tol in the function that attached and
that does what I believe that would have to make ' FileRename'. Of course, any
improvement in the function that attached would be received well.


Real MoveFile (Text origFile, Text destFile, Real delFileOrig)

{

Text origFileForm = ReplaceTable(origFile, [["/","\\"? ]]);
Text destFileForm = ReplaceTable(destFile, [["/","\\"? ]]);
Text sys_cmd = "COPY "+ origFileForm +" "+ destFileForm;
If(FileExist(origFile),{

If(Not(FileExist(destFile)),{

Real cop = System(sys_cmd);
If(cop == 0,{

WriteLn("<E>ERROR MoveFile: No se ha copiado el fichero "+

origFile +" en "+destFile+" .</E>");

0},{
WriteLn("El fichero "+origFile+" ha sido copiado en el destino "+destFile+" .");
If(delFileOrig != 0,{

Real del = FileDelete(origFile);
If(del == 1,{

WriteLn("El fichero "+origFile+" ha sido eliminado del camino de origen.");
1},{
WriteLn("<E>ERROR MoveFile: El fichero "+origFile+" no ha sido

eliminado del camino de origen .</E>");

0})},{

WriteLn("El fichero "+origFile+" no se elimina del camino de origen.");
1})})},{

Real updFileDest = TclYesNoQuestion("Confirmar el reemplazo de archivos",

"En la carpeta de destino ya existe un archivo con el

nombre "+destFile+". ¿Desea reemplazarlo?");

If (updFileDest != 0,{

Real cop = System(sys_cmd);
If(cop == 0,{

WriteLn("<E>ERROR MoveFile: No se ha copiado el fichero "+

origFile +" en "+destFile+" .</E>");

0},{
WriteLn("El fichero "+origFile+" ha sido copiado en el

destino "+destFile+" .");

If(delFileOrig != 0,{

Real del = FileDelete(origFile);
If(del == 1,{

WriteLn("El fichero "+origFile+" ha sido eliminado del camino de

origen.");

1},{
WriteLn("<E>ERROR MoveFile: El fichero "+origFile+" no ha sido

eliminado del camino de origen .</E>");

0})},{

WriteLn("El fichero "+origFile+" no se elimina del camino de origen.");
1})})},{

WriteLn("El fichero de origen "+origFile+" no se copia en el destino "+

destFile+" porque ya\n"+"existe un fichero en el destino con ese
nombre.");

1})})},{

WriteLn("<E>ERROR MoveFile: El fichero de origen "+ origFile +" no existe en"+

" el camino indicado .</E>");

0
})

};


PutDescription("
Mueve un fichero del camino de origen especificado origFile al camino de
destino especificado destFile. Toma como parámetros el fichero de origen
(con su ruta completa), el fichero de destino (ídem) y un booleano delFileOrig
que indica si una vez copiado el fichero en el destino queremos mantenerlo en
el origen ( delFileOrig = FALSE ) o preferimos borrarlo del origen
( delFileOrig = TRUE ). Asímismo, si en el destino ya existe un fichero con el
mismo nombre que el que queremos mover, pregunta si deseamos reemplazarlo y
hace lo que corresponda en función de si aceptamos o no.
Devuelve FALSE si durante el proceso se produce algún error y TRUE si todo
funciona correctamente con los parámetros que le hemos pasado a la función.",
MoveFile);

Change History (3)

comment:1 Changed 18 years ago by Víctor de Buen Remiro

Owner: changed from danirus to Víctor de Buen Remiro

comment:2 Changed 18 years ago by Víctor de Buen Remiro

Resolution: fixed
Status: newclosed

Sorry for this delayed answer.

FileRename works fine and fast when ypu want just to "rename" the file
I think this MoveFile function has not a general purpose and cannot be a built-in one. For example it doesn't works in unix.

When you want to delete the original file it would be easier and faster to call "move" command in windows or "mv" in linux, because no real deletion nor copy will be done. If you don't want to delete it then you simply want to copy it.

These are two very different concepts and I think it's not a very good idea to merge them in just one function.

Now, you can use functions OSFilMove and OSFilCopy that are provided in the TOL initLibrary\general\_system.tol. I recommend to use all this OS* functions to be more efficient and plattform independent.

Thanks to report.

comment:3 Changed 18 years ago by Víctor de Buen Remiro

bug_file_loc: http://www.tol-project.org
Note: See TracTickets for help on using tickets.