file properties

How can i read a files' size, extension and/or file type?

Comments

  • : 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.
Sign In or Register to comment.

Howdy, Stranger!

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

Categories

In this Discussion