Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

file properties

KASKAS Member Posts: 21
How can i read a files' size, extension and/or file type?

Comments

  • zibadianzibadian Member Posts: 6,349
    : How can i read a files' size, extension and/or file type?
    :
    FileSize() function
    ExtractFileExt() function

    The file type can be read in the registry under the CLASSES_ROOT. This key lists all the file types based on their extension. Below is a function, which opens the CLASSES_ROOT key and tries to open the correct file extension. If it fails it reports an "unknown type", otherwise it gives the string listed in the "content type"-key.
    [code]
    function GetFileType(FileExt: string): string;
    var
    Reg: TRegistry;
    begin
    Reg := TRegistry.Create(KEY_READ); // Open registry for reading
    with Reg do try
    Root := HKEY_CLASSES_ROOT; // Set the rootkey
    if OpenKeyReadOnly('.' + FileExt) then // try to find the extension
    Result := ReadString('Content Type') // if found return its type
    else
    Result := 'Unknown Type'; // else return a not found
    finally
    Reg.Free;
    end;
    end;
    [/code]
    See the help files for more info on these functions and objects.
  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ___ < http://forcoder.org /> free ebooks and video tutorials about < Python PL/SQL Go Delphi Ruby Visual Basic .NET JavaScript R MATLAB PHP Perl Assembly Swift Visual Basic C++ Scratch Objective-C C# C Java SAS Apex Fortran Ada Awk Clojure Lua Julia Scheme Prolog Dart COBOL F# Crystal Rust Kotlin Alice Lisp Erlang VBScript ABAP FoxPro Bash LabVIEW ML Transact-SQL Scala Hack D Logo /> ______

Sign In or Register to comment.