home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1993 #2
/
Image.iso
/
comm
/
brc_3asp.zip
/
ZIPCOMDT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-01-30
|
7KB
|
152 lines
program ZipCommentDate; {add comments to ZIP files from a file list
and change the date/time of the ZIP file to the
latest date/time of any file within}
{ This program was written by Bruce Clawson, Wauwatosa, WI USA.
The unit 'ZIPDIR.PAS' was picked up from the Atkinson Home Computer BBS
some time ago. As I can't find any docs for it I sincerely hope that
I am not violating anyone's rights by including it here.
My program (ZIPCOMDT.PAS) is released to the public domain. You are
free to use/abuse/modify/distribute it as you wish but please leave
this comment area intact. Direct comments to me on EXEC-PC. }
{ compiled with Borland's Turbo Pascal 6.0 }
{$M 16384,0,32768} {needed because of 'exec' command}
uses
dos, ZipDir; {I got the ZipDir unit from the Atkinson Home Computer BBS}
{I hope I am not violating anyone by including it here}
const
NameFileName = '#comment.###'; {name of the temporary file }
{ The ZIP file comment/description is written out to this file. }
{ PKZIP is called with the '-z' parameter to update the comment }
{ field and DOS redirection is used to have it read in the temp }
{ file in place of a keyboard entry. }
var
SrceFile : text; {logfile containing ZIP file names and comments}
NameFile : text; {temporary workfile}
function Exist (FileName : string): boolean; {does a file exist?}
var
DirInfo : SearchRec; {defined in the DOS unit}
begin
Exist := false;
FindFirst (FileName, Archive+ReadOnly, DirInfo);
if DosError = 0
then Exist := true; {yes, it exists}
end; {Function Exist}
procedure AskSrceName (var FileName : string);
begin
writeln;
write ('Enter Input Logfile Name: ');
readln (FileName);
end;
procedure Comments (PkZip : PathStr);
var
ZipFile : text; {the ZIP file itself}
ZipName : string; {name of ZIP file}
ZipDirItem : string; {ZIP directory item from 'ZIPDIR' unit}
SrceRec : string; {logfile record area}
Description : string; {Comment field from logfile}
CommandLine : string; {Command for DOS to execute}
ZfDaTi : longint; {file date/time in system format}
ZfDateTime : DateTime; {file date/time structure (DOS unit)}
ZipDateTime : string; {used to find newest member file}
TmpDateTime : string; {used to find newest member file}
ZipDirStatus : integer; {status returned by 'ZIPDIR' unit}
Sub : integer; {a counter}
begin
readln (SrceFile, SrceRec); {read a record from the logfile}
Sub := pos ('.ZIP', SrceRec); {where does '.ZIP' occur in the record?}
if (Sub = 0) or (Sub > 9) {if not at all or past column 9...}
then exit; {probably not a valid filename}
ZipName := copy (SrceRec,1,Sub+3); {extract ZIP filename}
if not Exist (ZipName) {does it exist?}
then exit; {if no then exit}
if length (SrceRec) > 27 {extract comment}
then Description := copy (SrceRec,28,length (SrceRec)-27);
rewrite (NameFile); {open the file output}
writeln (NameFile,Description); {write the comment to it}
close (NameFile); {close the file}
{note: I could not call PKZIP directly because of the redirection
in the command line. It works OK going through 'COMMAND.COM'.}
SwapVectors; {good form for 'exec' command}
exec (GetEnv ('COMSPEC'), ' /C ' + PkZip + ' -z ' + ZipName
+ ' <' + NameFileName + ' >NUL'); {call PKZIP}
SwapVectors; {good form for 'exec' command}
if (DosError <> 0) or (DosExitCode <> 0) {if something screwed up}
then writeln ('DosError = ', DosError,
'EXEC exit code = ', DosExitCode);
assign (ZipFile,ZipName); {assign the ZIP file}
reset (ZipFile); {open for input}
getftime (ZipFile,ZfDaTi); {get its date/time}
unpacktime (ZfDaTi, ZfDateTime); {convert to usable format}
ZipDateTime := '00000000000000'; {clear out}
ZipDirSetup (ZipName,ZipDirStatus); {do ZIP directory setup}
while ZipDirStatus = 0 do {until 'eof'}
begin
ZipDirFetch (ZipDirItem,ZipDirStatus); {get ZIP member file info}
TmpDateTime := copy (ZipDirItem,35,4) {year}
+ copy (ZipDirItem,29,2) {month}
+ copy (ZipDirItem,32,2) {day}
+ copy (ZipDirItem,40,2) {hour}
+ copy (ZipDirItem,43,2) {minute}
+ copy (ZipDirItem,46,2); {second}
if TmpDateTime > ZipDateTime {which is newer?}
then ZipDateTime := TmpDateTime;
end;
with ZfDateTime do {plug back into DOS.DateTime format}
begin
val (copy (ZipDateTime, 1,4),Year, Sub);
val (copy (ZipDateTime, 5,2),Month,Sub);
val (copy (ZipDateTime, 7,2),Day, Sub);
val (copy (ZipDateTime, 9,2),Hour, Sub);
val (copy (ZipDateTime,11,2),Min, Sub);
val (copy (ZipDateTime,13,2),Sec, Sub);
end;
packtime (ZfDateTime,ZfDaTi); {convert to system format}
setftime (ZipFile,ZfDaTi); {update disk directory values}
close (ZipFile); {close the file}
writeln;
while length (ZipName) < 14 do
ZipName := ZipName + ' '; {pad the name out to 14 characters}
write (ZipName, ' ');
write (copy (ZipDateTime,5,2), '-');
write (copy (ZipDateTime,7,2), '-');
write (copy (ZipDateTime,3,2), ' ');
writeln (Description); {show on screen}
end; {Comments}
{*********************************}
{-----MAINLINE PROGRAM CODING-----}
{*********************************}
var
SrceName : string; {name of logfile}
PkZip : PathStr; {full path name of PkZip program}
begin {MainProgram}
PkZip := fsearch ('PKZIP.EXE', GetEnv ('PATH'));
if PkZip = ''
then begin
writeln;
writeln ('Cannot find PKZIP.EXE!!! <program abort>');
halt (1);
end;
if (ParamStr (1) <> '') {logfile name on command line?}
then SrceName := ParamStr (1) {yes, use it}
else AskSrceName (SrceName); {no, ask for one}
if not Exist (SrceName) {if it can't be found}
then repeat AskSrceName (SrceName) {keep asking}
until Exist (SrceName); {until we get one}
assign (SrceFile,SrceName); {assign the logfile}
reset (SrceFile); {open the logfile for input}
assign (NameFile,NameFileName); {assign the temporary file}
while not eof (SrceFile)
do Comments (PkZip);
close (SrceFile);
if Exist (NameFileName)
then erase (NameFile); {erase the temp file if it exists}
end. {MainProgram}