ErrorDeSintaxis

Pequeños fragmentos de código fuente en distintos lenguajes de programación, agrupados por categorías.

Puedes buscar entre los fuentes existentes, o aportar los tuyos.

Pascal: Fecha y hora de un fichero

Cambiar la fecha y hora de un fichero, desde Turbo Pascal

Lenguaje: Pascal (compilador: Turbo Pascal 7)

Categoría: Ficheros

(* Fuente procedente de ErrorDeSintaxis.es *)
(* Cambiar la fecha y hora de un fichero, desde *)
(*  Turbo Pascal *)
(* Lenguaje: Pascal *)
(* Compilador: Turbo Pascal 7 *)
(* Nivel: Intermedio *)
(* Disponible desde 17/07/2011 *)
(* Aportado por Nacho *)
(* Autor original: Greg Estabrooks *)
(* Web original: http://www.kd5col.info/swag/FILES/0047.PAS.html *)

{*******************************************************************}
PROGRAM SetFileDateAndTimeDemo; { Jan 8/93, Greg Estabrooks.        }
USES CRT,                       { IMPORT Clrscr,Writeln.            }
     DOS;                       { IMPORT SetFTime,PackTime,DateTime,}
                                { GetTime,GetDate.                  }
VAR
   Hour,Min,Sec,Sec100 :WORD;   { Variables to hold current time.   }
   Year,Mon,Day,DayoW  :WORD;   { Variables to hold current date.   }
   F2Change :FILE;              { Handle for file to change.        }
   NewTime  :LONGINT;           { Longint Holding new Date/Time.    }
   FTime    :DateTime;          { For use with packtime.            }
BEGIN
  Clrscr;                       { Clear the screen.                 }
  GetTime(Hour,Min,Sec,Sec100); { Get Current System Time.          }
  GetDate(Year,Mon,Day,DayoW);  { Get Current System Date.          }
  FTime.Year := Year;           { Assign new year.                  }
  FTime.Month:= Mon;            { Assign new month.                 }
  FTime.Day := Day;             { Assign New Day.                   }
  FTime.Hour:= Hour;            { Assign New hour.                  }
  FTime.Min := Min;             { Assign New Minute.                }
  FTime.Sec := Sec;             { Assign New Seconds.               }
  PackTime(FTime,NewTime);      { Now covert Time/Date to a longint.}
  Assign(F2Change,ParamStr(1)); { Assign file handle to file to change.}
  Reset(F2Change);              { Open file for reading.            }
  SetFTime(F2Change,NewTime);   { Now change to our time.           }
  Close(F2Change);              { Close File.                       }
END.{SetFileDateAndTimeDemo}
{*******************************************************************}