﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
238	FileRename	sdelfresno	Víctor de Buen Remiro	"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);
////////////////////////////////////////////////////////////////////////////////"	enhancement	closed	normal		Math	head	minor	fixed		
