mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-13 15:15:51 +02:00
137 lines
5.1 KiB
ObjectPascal
137 lines
5.1 KiB
ObjectPascal
{ $Id$ }
|
|
{
|
|
/***************************************************************************
|
|
fileutil.pas
|
|
-----------
|
|
|
|
***************************************************************************/
|
|
|
|
*****************************************************************************
|
|
* *
|
|
* This file is part of the Lazarus Component Library (LCL) *
|
|
* *
|
|
* See the file COPYING.LCL, included in this distribution, *
|
|
* for details about the copyright. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
* *
|
|
*****************************************************************************
|
|
}
|
|
unit FileUtil;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
{$IF defined(VER2_0_2) and defined(win32)}
|
|
// FPC <= 2.0.2 compatibility code
|
|
// WINDOWS define was added after FPC 2.0.2
|
|
{$define WINDOWS}
|
|
{$endif}
|
|
|
|
interface
|
|
|
|
uses
|
|
// For Smart Linking: Do not use the LCL!
|
|
Classes, SysUtils, LCLStrConsts;
|
|
|
|
// file attributes and states
|
|
function CompareFilenames(const Filename1, Filename2: string): integer;
|
|
function CompareFilenames(const Filename1, Filename2: string;
|
|
ResolveLinks: boolean): integer;
|
|
function CompareFilenames(Filename1: PChar; Len1: integer;
|
|
Filename2: PChar; Len2: integer; ResolveLinks: boolean): integer;
|
|
function FilenameIsAbsolute(const TheFilename: string):boolean;
|
|
function FilenameIsWinAbsolute(const TheFilename: string):boolean;
|
|
function FilenameIsUnixAbsolute(const TheFilename: string):boolean;
|
|
procedure CheckIfFileIsExecutable(const AFilename: string);
|
|
procedure CheckIfFileIsSymlink(const AFilename: string);
|
|
function FileIsReadable(const AFilename: string): boolean;
|
|
function FileIsWritable(const AFilename: string): boolean;
|
|
function FileIsText(const AFilename: string): boolean;
|
|
function FileIsText(const AFilename: string; out FileReadable: boolean): boolean;
|
|
function FileIsExecutable(const AFilename: string): boolean;
|
|
function FileIsSymlink(const AFilename: string): boolean;
|
|
function FileSize(const Filename: string): int64;
|
|
function GetFileDescription(const AFilename: string): string;
|
|
function ReadAllLinks(const Filename: string;
|
|
ExceptionOnError: boolean): string;
|
|
|
|
// directories
|
|
function DirPathExists(const FileName: String): Boolean;
|
|
function ForceDirectory(DirectoryName: string): boolean;
|
|
function DeleteDirectory(const DirectoryName: string;
|
|
OnlyChilds: boolean): boolean;
|
|
function ProgramDirectory: string;
|
|
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
|
|
|
// filename parts
|
|
const
|
|
PascalFileExt: array[1..3] of string = ('.pas','.pp','.p');
|
|
|
|
function ExtractFileNameOnly(const AFilename: string): string;
|
|
function ExtractFileNameWithoutExt(const AFilename: string): string;
|
|
function CompareFileExt(const Filename, Ext: string;
|
|
CaseSensitive: boolean): integer;
|
|
function CompareFileExt(const Filename, Ext: string): integer;
|
|
function FilenameIsPascalUnit(const Filename: string): boolean;
|
|
function AppendPathDelim(const Path: string): string;
|
|
function ChompPathDelim(const Path: string): string;
|
|
function TrimFilename(const AFilename: string): string;
|
|
function CleanAndExpandFilename(const Filename: string): string;
|
|
function CleanAndExpandDirectory(const Filename: string): string;
|
|
function FileIsInPath(const Filename, Path: string): boolean;
|
|
function FileIsInDirectory(const Filename, Directory: string): boolean;
|
|
function FileInFilenameMasks(const Filename, Masks: string): boolean;
|
|
|
|
// file search
|
|
type
|
|
TSearchFileInPathFlag = (
|
|
sffDontSearchInBasePath,
|
|
sffSearchLoUpCase
|
|
);
|
|
TSearchFileInPathFlags = set of TSearchFileInPathFlag;
|
|
|
|
function GetAllFilesMask: string;
|
|
function SearchFileInPath(const Filename, BasePath, SearchPath,
|
|
Delimiter: string; Flags: TSearchFileInPathFlags): string;
|
|
function SearchAllFilesInPath(const Filename, BasePath, SearchPath,
|
|
Delimiter: string; Flags: TSearchFileInPathFlags): TStrings;
|
|
function FindDiskFilename(const Filename: string): string;
|
|
function FindDiskFileCaseInsensitive(const Filename: string): string;
|
|
|
|
// file actions
|
|
function ReadFileToString(const Filename: string): string;
|
|
function CopyFile(const SrcFilename, DestFilename: string): boolean;
|
|
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean): boolean;
|
|
function GetTempFilename(const Path, Prefix: string): string;
|
|
|
|
implementation
|
|
|
|
{$IFNDEF mswindows}
|
|
uses
|
|
Unix, BaseUnix;
|
|
{$ENDIF}
|
|
|
|
var
|
|
UpChars: array[char] of char;
|
|
|
|
|
|
{$I fileutil.inc}
|
|
|
|
procedure InternalInit;
|
|
var
|
|
c: char;
|
|
begin
|
|
for c:=Low(char) to High(char) do begin
|
|
UpChars[c]:=upcase(c);
|
|
end;
|
|
end;
|
|
|
|
initialization
|
|
InternalInit;
|
|
|
|
end.
|
|
|
|
|