System.IOUtils.TFile

提供: RAD Studio API Documentation
移動先: 案内検索

Delphi

  TFile = record
  private
    const
      FCMinFileNameLen = 12;
    class procedure InternalCheckFilePathParam(const Path: string;
        const FileExistsCheck: Boolean); static;
    class procedure CheckAppendAllTextParameters(const Path: string;
        const Encoding: TEncoding; const NeedEncoding: Boolean); static;
    class procedure CheckAppendTextParameters(const Path: string); inline; static;
    class procedure CheckCopyParameters(const SourceFileName,
        DestFileName: string; const Overwrite: Boolean); static;
    class procedure CheckCreateParameters(const Path: string); inline; static;
    class procedure CheckCreateTextParameters(const Path: string); inline; static;
{$IFDEF MSWINDOWS}
    class procedure CheckDecryptParameters(const Path: string); inline; static;
{$ENDIF MSWINDOWS}
    class procedure CheckDeleteParameters(const Path: string); inline; static;
{$IFDEF MSWINDOWS}
    class procedure CheckEncryptParameters(const Path: string); inline; static;
{$ENDIF MSWINDOWS}
    class procedure CheckGetAttributesParameters(const Path: string); inline; static;
    class procedure CheckGetCreationTimeParameters(const Path: string); inline; static;
    class procedure CheckGetCreationTimeUtcParameters(const Path: string); inline; static;
    class procedure CheckGetLastAccessTimeParameters(const Path: string); inline; static;
    class procedure CheckGetLastAccessTimeUtcParameters(const Path: string); inline; static;
    class procedure CheckGetLastWriteTimeParameters(const Path: string); inline; static;
    class procedure CheckGetLastWriteTimeUtcParameters(const Path: string); inline; static;
    class procedure CheckMoveParameters(const SourceFileName,
        DestFileName: string); static;
    class procedure CheckOpenParameters(const Path: string); inline; static;
    class procedure CheckOpenReadParameters(const Path: string); inline; static;
    class procedure CheckOpenTextParameters(const Path: string); inline; static;
    class procedure CheckOpenWriteParameters(const Path: string); inline; static;
    class procedure CheckReadAllBytesParameters(const Path: string); inline; static;
    class procedure CheckReadAllLinesParameters(const Path: string;
        const Encoding: TEncoding; const NeedEncoding: Boolean); static;
    class procedure CheckReadAllTextParameters(const Path: string;
        const Encoding: TEncoding; const NeedEncoding: Boolean); static;
{$IFDEF MSWINDOWS}
    class procedure CheckReplaceParameters(const SourceFileName,
        DestinationFileName, DestinationBackupFileName: string); static;
{$ENDIF MSWINDOWS}
    class procedure CheckSetAttributesParameters(const Path: string); inline; static;
    class procedure CheckSetCreationTimeParameters(const Path: string); inline; static;
    class procedure CheckSetCreationTimeUtcParameters(const Path: string); inline; static;
    class procedure CheckSetLastAccessTimeParameters(const Path: string); inline; static;
    class procedure CheckSetLastAccessTimeUtcParameters(const Path: string); inline; static;
    class procedure CheckSetLastWriteTimeParameters(const Path: string); inline; static;
    class procedure CheckSetLastWriteTimeUtcParameters(const Path: string); inline; static;
    class procedure CheckWriteAllBytesParameters(const Path: string); inline; static;
    class procedure CheckWriteAllLinesParameters(const Path: string;
        const Encoding: TEncoding; const NeedEncoding: Boolean); static;
    class procedure CheckWriteAllTextParameters(const Path: string;
        const Encoding: TEncoding; const NeedEncoding: Boolean); static;
    class function GetEncoding(const Stream: TStream): TEncoding; static;
    class function GetStringArrayFromText(const Text: string): TStringDynArray; static;
    class function GetStringListFromArray(const AnArray: TStringDynArray): TStringList; static;
    class function DoCreateOpenFile(const Path: string): TFileStream; static;
    class function DoCopy(const SourceFileName, DestFileName: string;
        const Overwrite: Boolean): Boolean; {$IFDEF MSWINDOWS} inline; {$ENDIF} static;
    class function DoGetAttributes(const Path: string; FollowLink: Boolean = True): TFileAttributes; {$IFDEF MSWINDOWS}inline;{$ENDIF} static;
    class function DoReadAllBytes(const Path: string): TBytes; static;
    class function DoReadAllText(const Path: string): string; overload; static;
    class function DoReadAllText(const Path: string;
        const Encoding: TEncoding): string; overload; static;
    class procedure DoSetAttributes(const Path: string;
        const Attributes: TFileAttributes); {$IFDEF MSWINDOWS}inline;{$ENDIF} static;
    class procedure DoWriteAllText(const Path, Contents: string;
        const Encoding: TEncoding; const WriteBOM: Boolean); static;
    class procedure DoWriteAllLines(const Path: string;
        const Contents: TStringDynArray; const Encoding: TEncoding;
        const WriteBOM: Boolean); static;
  public
    class function IntegerToFileAttributes(const Attributes: Integer): TFileAttributes; static;
    class function FileAttributesToInteger(const Attributes: TFileAttributes): Integer; static;
    class function Create(const Path: string): TFileStream; overload; inline; static;
    class function Create(const Path: string; const BufferSize: Integer): TFileStream; overload; static;
    class procedure AppendAllText(const Path, Contents: string); overload; static;
    class procedure AppendAllText(const Path, Contents: string;
        const Encoding: TEncoding); overload; static;
    class function AppendText(const Path: string): TStreamWriter; static;
    class procedure Copy(const SourceFileName, DestFileName: string);
        overload; inline; static;
    class procedure Copy(const SourceFileName, DestFileName: string;
        const Overwrite: Boolean); overload; static;
    class function CreateSymLink(const Link, Target: string): Boolean; static;
    class function CreateText(const Path: string): TStreamWriter; static;
{$IFDEF MSWINDOWS}
    class procedure Decrypt(const Path: string); static;
{$ENDIF MSWINDOWS}
    class procedure Delete(const Path: string); static;
{$IFDEF MSWINDOWS}
    class procedure Encrypt(const Path: string); static;
{$ENDIF MSWINDOWS}
    class function Exists(const Path: string; FollowLink: Boolean = True): Boolean; inline; static;
    class function GetSize(const Path: string): Int64; static;
    class function GetAttributes(const Path: string; FollowLink: Boolean = True): TFileAttributes; inline; static;
    class function GetCreationTime(const Path: string): TDateTime; inline; static;
    class function GetCreationTimeUtc(const Path: string): TDateTime; inline; static;
    class function GetLastAccessTime(const Path: string): TDateTime; inline; static;
    class function GetLastAccessTimeUtc(const Path: string): TDateTime; inline; static;
    class function GetLastWriteTime(const Path: string): TDateTime; inline; static;
    class function GetLastWriteTimeUtc(const Path: string): TDateTime; inline; static;
    class function GetSymLinkTarget(const FileName: string;
      var SymLinkRec: TSymLinkRec): Boolean; overload; static;
    class function GetSymLinkTarget(const FileName: string;
      var TargetName: string): Boolean; overload; static;
    class procedure Move(SourceFileName, DestFileName: string); static;
    class function Open(const Path: string;
      const Mode: TFileMode): TFileStream; overload; inline; static;
    class function Open(const Path: string;
        const Mode: TFileMode; const Access: TFileAccess): TFileStream;
        overload; inline; static;
    class function Open(const Path: string;
        const Mode: TFileMode; const Access: TFileAccess;
        const Share: TFileShare): TFileStream; overload; static;
    class function OpenRead(const Path: string): TFileStream; static;
    class function OpenText(const Path: string): TStreamReader; static;
    class function OpenWrite(const Path: string): TFileStream; static;
    class function ReadAllBytes(const Path: string): TBytes; static;
    class function ReadAllLines(const Path: string): TStringDynArray;
        overload; static;
    class function ReadAllLines(const Path: string;
        const Encoding: TEncoding): TStringDynArray; overload; static;
    class function ReadAllText(const Path: string): string; overload; inline; static;
    class function ReadAllText(const Path: string;
      const Encoding: TEncoding): string; overload; inline; static;
    class procedure Replace(const SourceFileName, DestinationFileName,
        DestinationBackupFileName: string); overload; {$IFDEF MSWINDOWS}inline; {$ENDIF} static;
{$IFDEF MSWINDOWS}
    class procedure Replace(SourceFileName, DestinationFileName,
        DestinationBackupFileName: string; const IgnoreMetadataErrors: Boolean);
        overload; static;
{$ENDIF MSWINDOWS}
    class procedure SetAttributes(const Path: string;
        const Attributes: TFileAttributes); inline; static;
    class procedure SetCreationTime(const Path: string;
        const CreationTime: TDateTime); inline; static;
    class procedure SetCreationTimeUtc(const Path: string;
        const CreationTime: TDateTime); inline; static;
    class procedure SetLastAccessTime(const Path: string;
        const LastAccessTime: TDateTime); inline; static;
    class procedure SetLastAccessTimeUtc(const Path: string;
        const LastAccessTime: TDateTime); inline; static;
    class procedure SetLastWriteTime(const Path: string;
        const LastWriteTime: TDateTime); inline; static;
    class procedure SetLastWriteTimeUtc(const Path: string;
        const LastWriteTime: TDateTime); inline; static;
    class procedure WriteAllBytes(const Path: string; const Bytes: TBytes); static;
    class procedure WriteAllLines(const Path: string;
        const Contents: TStringDynArray); overload; inline; static;
    class procedure WriteAllLines(const Path: string;
        const Contents: TStringDynArray; const Encoding: TEncoding); overload; static;
    class procedure WriteAllText(const Path, Contents: string); overload; static;
    class procedure WriteAllText(const Path, Contents: string;
        const Encoding: TEncoding); overload; static;
  end;

C++

struct DECLSPEC_DRECORD TFile
{
private:
    static const System::Int8 FCMinFileNameLen = System::Int8(0xc);
    static void __fastcall InternalCheckFilePathParam(const System::UnicodeString Path, const bool FileExistsCheck);
    static void __fastcall CheckAppendAllTextParameters(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding, const bool NeedEncoding);
    static void __fastcall CheckAppendTextParameters(const System::UnicodeString Path);
    static void __fastcall CheckCopyParameters(const System::UnicodeString SourceFileName, const System::UnicodeString DestFileName, const bool Overwrite);
    static void __fastcall CheckCreateParameters(const System::UnicodeString Path);
    static void __fastcall CheckCreateTextParameters(const System::UnicodeString Path);
    static void __fastcall CheckDecryptParameters(const System::UnicodeString Path);
    static void __fastcall CheckDeleteParameters(const System::UnicodeString Path);
    static void __fastcall CheckEncryptParameters(const System::UnicodeString Path);
    static void __fastcall CheckGetAttributesParameters(const System::UnicodeString Path);
    static void __fastcall CheckGetCreationTimeParameters(const System::UnicodeString Path);
    static void __fastcall CheckGetCreationTimeUtcParameters(const System::UnicodeString Path);
    static void __fastcall CheckGetLastAccessTimeParameters(const System::UnicodeString Path);
    static void __fastcall CheckGetLastAccessTimeUtcParameters(const System::UnicodeString Path);
    static void __fastcall CheckGetLastWriteTimeParameters(const System::UnicodeString Path);
    static void __fastcall CheckGetLastWriteTimeUtcParameters(const System::UnicodeString Path);
    static void __fastcall CheckMoveParameters(const System::UnicodeString SourceFileName, const System::UnicodeString DestFileName);
    static void __fastcall CheckOpenParameters(const System::UnicodeString Path);
    static void __fastcall CheckOpenReadParameters(const System::UnicodeString Path);
    static void __fastcall CheckOpenTextParameters(const System::UnicodeString Path);
    static void __fastcall CheckOpenWriteParameters(const System::UnicodeString Path);
    static void __fastcall CheckReadAllBytesParameters(const System::UnicodeString Path);
    static void __fastcall CheckReadAllLinesParameters(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding, const bool NeedEncoding);
    static void __fastcall CheckReadAllTextParameters(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding, const bool NeedEncoding);
    static void __fastcall CheckReplaceParameters(const System::UnicodeString SourceFileName, const System::UnicodeString DestinationFileName, const System::UnicodeString DestinationBackupFileName);
    static void __fastcall CheckSetAttributesParameters(const System::UnicodeString Path);
    static void __fastcall CheckSetCreationTimeParameters(const System::UnicodeString Path);
    static void __fastcall CheckSetCreationTimeUtcParameters(const System::UnicodeString Path);
    static void __fastcall CheckSetLastAccessTimeParameters(const System::UnicodeString Path);
    static void __fastcall CheckSetLastAccessTimeUtcParameters(const System::UnicodeString Path);
    static void __fastcall CheckSetLastWriteTimeParameters(const System::UnicodeString Path);
    static void __fastcall CheckSetLastWriteTimeUtcParameters(const System::UnicodeString Path);
    static void __fastcall CheckWriteAllBytesParameters(const System::UnicodeString Path);
    static void __fastcall CheckWriteAllLinesParameters(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding, const bool NeedEncoding);
    static void __fastcall CheckWriteAllTextParameters(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding, const bool NeedEncoding);
    static System::Sysutils::TEncoding* __fastcall GetEncoding(System::Classes::TStream* const Stream);
#ifndef _WIN64
    static System::DynamicArray<System::UnicodeString> __fastcall GetStringArrayFromText(const System::UnicodeString Text);
    static System::Classes::TStringList* __fastcall GetStringListFromArray(const System::DynamicArray<System::UnicodeString> AnArray);
#else /* _WIN64 */
    static System::TArray__1<System::UnicodeString> __fastcall GetStringArrayFromText(const System::UnicodeString Text);
    static System::Classes::TStringList* __fastcall GetStringListFromArray(const System::TArray__1<System::UnicodeString> AnArray);
#endif /* _WIN64 */
    static System::Classes::TFileStream* __fastcall DoCreateOpenFile(const System::UnicodeString Path);
    static bool __fastcall DoCopy(const System::UnicodeString SourceFileName, const System::UnicodeString DestFileName, const bool Overwrite);
    static TFileAttributes __fastcall DoGetAttributes(const System::UnicodeString Path, bool FollowLink = true);
#ifndef _WIN64
    static System::DynamicArray<System::Byte> __fastcall DoReadAllBytes(const System::UnicodeString Path);
#else /* _WIN64 */
    static System::TArray__1<System::Byte> __fastcall DoReadAllBytes(const System::UnicodeString Path);
#endif /* _WIN64 */
    static System::UnicodeString __fastcall DoReadAllText(const System::UnicodeString Path)/* overload */;
    static System::UnicodeString __fastcall DoReadAllText(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding)/* overload */;
    static void __fastcall DoSetAttributes(const System::UnicodeString Path, const TFileAttributes Attributes);
    static void __fastcall DoWriteAllText(const System::UnicodeString Path, const System::UnicodeString Contents, System::Sysutils::TEncoding* const Encoding, const bool WriteBOM);
#ifndef _WIN64
    static void __fastcall DoWriteAllLines(const System::UnicodeString Path, const System::DynamicArray<System::UnicodeString> Contents, System::Sysutils::TEncoding* const Encoding, const bool WriteBOM);
#else /* _WIN64 */
    static void __fastcall DoWriteAllLines(const System::UnicodeString Path, const System::TArray__1<System::UnicodeString> Contents, System::Sysutils::TEncoding* const Encoding, const bool WriteBOM);
#endif /* _WIN64 */
public:
    static TFileAttributes __fastcall IntegerToFileAttributes(const int Attributes);
    static int __fastcall FileAttributesToInteger(const TFileAttributes Attributes);
    static System::Classes::TFileStream* __fastcall Create(const System::UnicodeString Path)/* overload */;
    static System::Classes::TFileStream* __fastcall Create(const System::UnicodeString Path, const int BufferSize)/* overload */;
    static void __fastcall AppendAllText(const System::UnicodeString Path, const System::UnicodeString Contents)/* overload */;
    static void __fastcall AppendAllText(const System::UnicodeString Path, const System::UnicodeString Contents, System::Sysutils::TEncoding* const Encoding)/* overload */;
    static System::Classes::TStreamWriter* __fastcall AppendText(const System::UnicodeString Path);
    static void __fastcall Copy(const System::UnicodeString SourceFileName, const System::UnicodeString DestFileName)/* overload */;
    static void __fastcall Copy(const System::UnicodeString SourceFileName, const System::UnicodeString DestFileName, const bool Overwrite)/* overload */;
    static bool __fastcall CreateSymLink(const System::UnicodeString Link, const System::UnicodeString Target);
    static System::Classes::TStreamWriter* __fastcall CreateText(const System::UnicodeString Path);
    static void __fastcall Decrypt(const System::UnicodeString Path);
    static void __fastcall Delete(const System::UnicodeString Path);
    static void __fastcall Encrypt(const System::UnicodeString Path);
    static bool __fastcall Exists(const System::UnicodeString Path, bool FollowLink = true);
    static __int64 __fastcall GetSize(const System::UnicodeString Path);
    static TFileAttributes __fastcall GetAttributes(const System::UnicodeString Path, bool FollowLink = true);
    static System::TDateTime __fastcall GetCreationTime(const System::UnicodeString Path);
    static System::TDateTime __fastcall GetCreationTimeUtc(const System::UnicodeString Path);
    static System::TDateTime __fastcall GetLastAccessTime(const System::UnicodeString Path);
    static System::TDateTime __fastcall GetLastAccessTimeUtc(const System::UnicodeString Path);
    static System::TDateTime __fastcall GetLastWriteTime(const System::UnicodeString Path);
    static System::TDateTime __fastcall GetLastWriteTimeUtc(const System::UnicodeString Path);
    static bool __fastcall GetSymLinkTarget(const System::UnicodeString FileName, System::Sysutils::TSymLinkRec &SymLinkRec)/* overload */;
    static bool __fastcall GetSymLinkTarget(const System::UnicodeString FileName, System::UnicodeString &TargetName)/* overload */;
    static void __fastcall Move(System::UnicodeString SourceFileName, System::UnicodeString DestFileName);
    static System::Classes::TFileStream* __fastcall Open(const System::UnicodeString Path, const TFileMode Mode)/* overload */;
    static System::Classes::TFileStream* __fastcall Open(const System::UnicodeString Path, const TFileMode Mode, const TFileAccess Access)/* overload */;
    static System::Classes::TFileStream* __fastcall Open(const System::UnicodeString Path, const TFileMode Mode, const TFileAccess Access, const TFileShare Share)/* overload */;
    static System::Classes::TFileStream* __fastcall OpenRead(const System::UnicodeString Path);
    static System::Classes::TStreamReader* __fastcall OpenText(const System::UnicodeString Path);
    static System::Classes::TFileStream* __fastcall OpenWrite(const System::UnicodeString Path);
#ifndef _WIN64
    static System::DynamicArray<System::Byte> __fastcall ReadAllBytes(const System::UnicodeString Path);
    static System::DynamicArray<System::UnicodeString> __fastcall ReadAllLines(const System::UnicodeString Path)/* overload */;
    static System::DynamicArray<System::UnicodeString> __fastcall ReadAllLines(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding)/* overload */;
#else /* _WIN64 */
    static System::TArray__1<System::Byte> __fastcall ReadAllBytes(const System::UnicodeString Path);
    static System::TArray__1<System::UnicodeString> __fastcall ReadAllLines(const System::UnicodeString Path)/* overload */;
    static System::TArray__1<System::UnicodeString> __fastcall ReadAllLines(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding)/* overload */;
#endif /* _WIN64 */
    static System::UnicodeString __fastcall ReadAllText(const System::UnicodeString Path)/* overload */;
    static System::UnicodeString __fastcall ReadAllText(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding)/* overload */;
    static void __fastcall Replace(const System::UnicodeString SourceFileName, const System::UnicodeString DestinationFileName, const System::UnicodeString DestinationBackupFileName)/* overload */;
    static void __fastcall Replace(System::UnicodeString SourceFileName, System::UnicodeString DestinationFileName, System::UnicodeString DestinationBackupFileName, const bool IgnoreMetadataErrors)/* overload */;
    static void __fastcall SetAttributes(const System::UnicodeString Path, const TFileAttributes Attributes);
    static void __fastcall SetCreationTime(const System::UnicodeString Path, const System::TDateTime CreationTime);
    static void __fastcall SetCreationTimeUtc(const System::UnicodeString Path, const System::TDateTime CreationTime);
    static void __fastcall SetLastAccessTime(const System::UnicodeString Path, const System::TDateTime LastAccessTime);
    static void __fastcall SetLastAccessTimeUtc(const System::UnicodeString Path, const System::TDateTime LastAccessTime);
    static void __fastcall SetLastWriteTime(const System::UnicodeString Path, const System::TDateTime LastWriteTime);
    static void __fastcall SetLastWriteTimeUtc(const System::UnicodeString Path, const System::TDateTime LastWriteTime);
#ifndef _WIN64
    static void __fastcall WriteAllBytes(const System::UnicodeString Path, const System::DynamicArray<System::Byte> Bytes);
    static void __fastcall WriteAllLines(const System::UnicodeString Path, const System::DynamicArray<System::UnicodeString> Contents)/* overload */;
    static void __fastcall WriteAllLines(const System::UnicodeString Path, const System::DynamicArray<System::UnicodeString> Contents, System::Sysutils::TEncoding* const Encoding)/* overload */;
#else /* _WIN64 */
    static void __fastcall WriteAllBytes(const System::UnicodeString Path, const System::TArray__1<System::Byte> Bytes);
    static void __fastcall WriteAllLines(const System::UnicodeString Path, const System::TArray__1<System::UnicodeString> Contents)/* overload */;
    static void __fastcall WriteAllLines(const System::UnicodeString Path, const System::TArray__1<System::UnicodeString> Contents, System::Sysutils::TEncoding* const Encoding)/* overload */;
#endif /* _WIN64 */
    static void __fastcall WriteAllText(const System::UnicodeString Path, const System::UnicodeString Contents)/* overload */;
    static void __fastcall WriteAllText(const System::UnicodeString Path, const System::UnicodeString Contents, System::Sysutils::TEncoding* const Encoding)/* overload */;
};

プロパティ

種類 可視性 ソース ユニット
record
struct
public
System.IOUtils.pas
System.IOUtils.hpp
System.IOUtils System.IOUtils

説明

ファイル操作に使用する静的なユーティリティ メソッドを多数含んでいます。

TFile は、ファイルに対してさまざまな操作を行うための静的メソッドだけを含むレコードです。TFile にはインスタンス メソッドやインスタンス フィールドがないため、TFile 型の変数を宣言しないでください。TFile を使って実行できる操作には、次のようなものがあります。

  • ファイルの作成、名前変更、削除。
  • ファイル内容に対する簡略化されたアクセス。
  • ファイルの属性やタイムスタンプの操作。

メモ:  TFile が公開しているメソッドのほとんどは、.NET FrameworkFile クラスが公開しているメソッドと互換性のあるシグニチャになっています。

関連項目