EFIO, Auxilary file and filename handling

EFIO is a (up till now) rather simple unit, in which I stored all leftover routines concerning files (and filenames).

The more advanced file-handling (like directory searching) is situated in EDirTree



Types

EFIO currently only has one type, ArchiveType:

TYPE

   ArchiveType = ( none,SQZ, ZIP, HPK, ZOO, LZH,
                   ARJ, DWC, ARC, PAK, A7P, HYP,
                   RAR,   Q, UC2, Gif, LBM, PCX,
                   WAV, BMP);

This ordinal type is used by ArchiveMethod to indicate the archivetype.



PROCEDURES



ArchiveMethod

Declaration

FUNCTION ArchiveMethod( FileName : String) : ArchiveType;

Description

Returns the archive/file type of the filename passed as a parameter.

Right now the following types are supported, or at least prepared in the type.

ARJ, ZIP, LZH, UC2,RARimplemented and tested
SQZ, HPK, Zooare implemented but untested
ARC, PAK, A7P, HYPtunimplemented, but I have some routines for these packers, but I have to decrypt the assembler
DWCNo algoritm present, only included in type because somebody said he had a detectionprocedure, but he never send it
GIF, LBM, PCX, WAV, BMPImplemented and seems to work. Most of these formats come in different flavours, so an additional detection routine might be necessary.

See Also ArchiveType

Notes



FileExists

Declaration

FUNCTION FileExists(FileName: String): Boolean;

Description

A boolean function that returns True if the file exists, otherwise, it returns False. Closes the file if it exists, copied from the BP7 help.

Note : Seems not to work for a directory.



ExtensionPos

Declaration

FUNCTION ExtensionPos ( CONST s : String) : WORD;

Description

Returns the position of the extension in path s, or MAX(WORD) (=65535) if not found. Actually this procedure was internal, but the procedure can be used to check if extension exists, so I moved it to the interface.

See Also:



RemoveExtension

Declaration

PROCEDURE RemoveExtension ( VAR s : String) ;

Description

Strip extension from path in S.

See Also:



AddExtension

Declaration

PROCEDURE AddExtension ( VAR s : String; CONST Extension : String) ;

Description

Append Extension to path in s. Path isn't allowed to have an extension.

See Also:



ChangeExtension

Declaration

PROCEDURE ChangeExtension ( VAR s : String; CONST Extension : String) ;

Description

Change the (potentially existant) extension of S to Extension

See Also:



DelDir

CAUTION, THIS IS A DANGEROUS COMMAND, USE WITH CARE!

Declaration

PROCEDURE Deldir(Dir : PathStr);

Description

Recursively removes all contents of DIR, hidden files and directories inclusive, like MsDos Deltree, or Linux rm -rf.

Note :



WrHex

Declaration

PROCEDURE WrHex (InValue:WORD); or

PROCEDURE WrHex (VAR F : Text;InValue:WORD);

Description

Write the WORD-typed value in an hexadecimal representation to either screen or text-file. The procedure always outputs 4 characters, left-padded with 0.

See Also:



WrLngHex

Declaration

PROCEDURE WrLngHex(InValue:CARDINAL); or

PROCEDURE WrLngHex(VAR F:Text;InValue:CARDINAL);

Description

Write the CARDINAL-typed value in an hexadecimal representation to either screen or text-file. The procedure always outputs 8 characters, left-padded with 0.

See Also:



WrOct

Declaration

PROCEDURE WrOct (InValue:WORD); or

PROCEDURE WrOct (VAR F : Text;InValue:WORD);

Description

Write the WORD-typed value as in an octal representation to either screen or text-file. The procedure always outputs 6 (16/3=5.3, rounded up) characters, left-padded with 0.

See Also:



WrLngOct

Declaration

PROCEDURE WrLngOct(InValue:CARDINAL); or

PROCEDURE WrLngOct(VAR F:Text;InValue:CARDINAL);

Description

Write the CARDINAL-typed value as in an octal representation to either screen or text-file. The procedure always outputs 11 (32/3 rounded up) characters, left-padded with 0.

See Also:



WrBinary

Declaration

PROCEDURE WrBinary (InValue:WORD); or

PROCEDURE WrBinary (VAR F : Text;InValue:WORD);

Description

Write the WORD-typed value in a binary representation to either screen or text-file. The procedure always outputs 16 characters, left-padded with 0.

See Also:



WrLngBinary

Declaration

PROCEDURE WrLngBinary (InValue:CARDINAL); or

PROCEDURE WrLngBinary (VAR F:Text;InValue:CARDINAL);

Description

Write the CARDINAL-typed value in a binary representation to either screen or text-file. The procedure always outputs 32 characters, left-padded with 0.

See Also:



WrStrAdj

Declaration

PROCEDURE WrStrAdj(CONST InS: String;L : LONGINT);
PROCEDURE WrStrAdj(VAR F: Text;CONST InS: String;L : LONGINT);

Description

Assuming that S is type STRING, WrStrAdj(S,L). Is the same as write(S:L), however WrStrAdj(S:-L) pads on the other side.



FileAppend

Declaration

PROCEDURE FileAppend(VAR F: Text;FileName:String);

Description

Roughly equal to:

Assign (F,FileName);
Append (F);
but this function creates the file if it doesn't exist, instead of a runtime error.

Example:

VAR F: Text;

BEGIN
 FileAppend(F,'system.log');  {Append, create if not exists}
 Writeln(F,'New Entry');
 Close(F);
END.


MkFullDir

Declaration

PROCEDURE MkFullDir(CONST InPath:String);

Description

Shell to MkDir command, creates several directories at once:

MkFullDir('D:\programming\FPC\RELEASE\0.99.8/Binaries'); creates the entire path, even if d:\programming doesn't exist. D: has to exist however.

The procedure only tries to create the right directory separator. It accepts both back- as forward slashes, and only outputs (to mkdir) backslashes(dos) or forwardslashes (Linux). I don't think this is necessary under FPC (the entire RTL allows both forward as backward slashes), but it might ease porting units back to Borland Pascal.

Based on the following RTL procedures : FindFirst, MkDir and FExpand. Errors(e.g. non existing driveletters) are handled by those procedures

Example:


BEGIN
 MkFullDir('c:\program files\XtdFpc Soft\XtdFpc\Libsrc\');
END.


Touch

Declaration

PROCEDURE Touch(Const FileName:String);

Description

Simply touch command (Set filetimedate of file(s) to current datetime). Directories and wildcards supported. NOT recursive. Use EdirTree to run a procedure recursive.

Example:


BEGIN
 Touch('c:\program files\*.*');
END.