Funciones de manejo de ficheros declaradas en ficheros de nombre fil.tol.
Las funciones de esta página están ordenadas de forma alfabética por las diferentes gramáticas del lenguaje Tol (
Text, Set, Serie, Anything, Code, Date, Real,...) y,
dentro de cada gramática, por el nombre de la función.
Pueden encontrarse 2 o más funciones con idéntico nombre,
pero con distintas maneras de programarse o con diferentes comentarios en diferentes idiomas,
estas funciones aparecerán unas a continuación de las otras.
//////////////////////////////////////////////////////////////////////////////
Real FilCheckExtension(Text filPth, // Ruta del fichero
Text txtExt, // Extension para comprobar
Real casSen) // Si distingue mayus/minus en extension
//////////////////////////////////////////////////////////////////////////////
{
Text filExt = If(casSen, GetFileExtension(filPth),
ToLower(GetFileExtension(filPth)));
Text chkExt = If(casSen, txtExt,
ToLower(txtExt));
filExt==chkExt
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna cierto si el fichero de ruta filPth tiene la extension txtExt.
Si casSen es cierto distingue entre mayusculas de minusculas.",
FilCheckExtension);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real FilCopy(Text oldPth, // Ruta del fichero origen
Text newPth, // Ruta del fichero destino
Real overwrite) // Si cierto sobre-escribe
//////////////////////////////////////////////////////////////////////////////
{
Text cpyTxt = "copy "+oldPth+" "+newPth;
Text cpyCmd = Replace(cpyTxt, "/", "\\");
Case(
Not(FileExist(oldPth)), FALSE, // Original doesn't exist
oldPth==newPth, FALSE, // Auto-copy ?
Not(FileExist(newPth)), System(cpyCmd), // Execute copy
overwrite, System(cpyCmd), // Copy and overwrite
FALSE) // Don't overwrite
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns TRUE in the file oldNam can be copied over newNam.",
FilCopy);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real FilDelete(Text filPth)
//////////////////////////////////////////////////////////////////////////////
{
If(FileExist(filPth), FileDelete(filPth), FALSE)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns TRUE in the file filPth can be deleted.",
FilDelete);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real FilRename(Text oldNam, Text newNam, Real overwrite)
//////////////////////////////////////////////////////////////////////////////
{
If(Not(FileExist(oldNam)), FALSE,
If(oldNam==newNam, FALSE,
{
If(Not(FileExist(newNam)), FileRename(oldNam,newNam),
If(overwrite, { FileDelete(newNam);
FileRename(oldNam,newNam) },
FALSE))
}))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns TRUE in the file oldNam can be renamed ad newNam.
If overwrite is TRUE the overwrite the target file.",
FilRename);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real FilTextFind(Text filPth, // Ruta de un fichero
Text fndTxt) // Texto a buscar
//////////////////////////////////////////////////////////////////////////////
{ If(!FileExist(filPth), 0, TextFind(ReadFile(filPth), fndTxt)) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna la posicion de un texto dentro de un fichero
Es similar a TextFind() pero para ficheros.",
FilDelExtLow);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real FilWriteIfDiff(Text filPth, // Fichero de salida
Text txtNew) // Texto para escribir
//////////////////////////////////////////////////////////////////////////////
{
If(! FileExist(filPth), { Text WriteFile(filPth, txtNew); TRUE },
If(txtNew != ReadFile(filPth), { Text WriteFile(filPth, txtNew); TRUE },
FALSE ))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Escribe txtOut en filPth si filPth es un nuevo fichero o si su contenido
actual es diferente de txtOut y en otro caso no escribe nada.
Retorna true si lo ha escrito y false si no ha sido necesario hacerlo.
Evita que los ficheros adquiran una fecha de actualizacion reciente
cuando su contenido no ha cambiando realmente, evitando, por ejemplo,
retransmisiones por ftp de fichero que realmente no han cambiado.",
FilWriteIfDiff);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text FilBetween2Tag(Text filPth, // Ruta de un fichero
Text tagIni, // Tag inicial
Text tagEnd) // Tag final
//////////////////////////////////////////////////////////////////////////////
{
If(!FileExist(filPth), "", // Nada si el fichero no existe
If(And(tagIni=="", tagEnd==""),
ReadFile(filPth), // Todo el fichero
TxtBetween2Tag(ReadFile(filPth), tagIni, tagEnd, FALSE))) // No compacta
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo resultado de reconvertir &, < y >.",
FilBetween2Tag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text FilDelExtLow(Text namFil)
//////////////////////////////////////////////////////////////////////////////
{ Replace(ToLower(namFil),".","_") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un nombre de fichero cambiando el . de la extension y cualquier otro
punto por un subrayador y pasandolo a minusculas.",
FilDelExtLow);
//////////////////////////////////////////////////////////////////////////////
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio