?
Solved

Fileaccess

Posted on 2003-02-26
9
Medium Priority
?
158 Views
Last Modified: 2010-04-04
When you click on the right mouse button on a file
--> properties
then you see the properties like: filetype, description, lokation, Size,...



var Rec: Tseachrec
Size:=Rec.Size;

but how can i get access to the other properties?
The main think I want to know is the property: description, it gives te name op a program-file.
0
Comment
Question by:Steve2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 2

Expert Comment

by:Tvigep
ID: 8032671
hi Steve,

This 'extra' info is actually extracted from the Registry. You'll have to use ExtractFileExt to get the extension of the filename, then query HKEY_CLASSES_ROOT for this extension (for example .dgn:HKEY_CLASSES_ROOT\.dgn).
it depends a bit on what you find there (it might be a ShellEx key, which would lead you to a CLSID, which would make it more difficult to get that info), but usually the description of the file type is in the Default key of the extension, so for example:
HKEY_CLASSES_ROOT\.dgn\(Default) = MicroStation DGN File which is the description you want to see.

As I said before, it might become more complicated if there is no value for the (Default) key, in which case you'll have to look up the CLSID I guess. There might be a function that does this, maybe in the WINAPI or something. You could check the ShellCtrls example (C:\Program Files\Borland\Delphi6\Demos\ShellControls\ShellCtrls.pas), they do something with this in there as well, it might help you figure out how to do this quicker.

HTH,
Stef
0
 

Author Comment

by:Steve2000
ID: 8037245
Would you please write a little code, i don't understand it 100%
0
 
LVL 2

Expert Comment

by:Tvigep
ID: 8055828
Steve,

This example assumes a form with a File Open dialog and an editfield on it, plus a normal button. it is the simplest form, not all fileextension descriptions will be found this way as I explained in my previous post. But this might get you on your way.

HTH,
Stef

Uses Registry;

procedure TForm1.Button1Click(Sender: TObject);
var FnameExtension:string;
    Reg:TRegistry;
begin
  If OpenDialog1.Execute then
  begin
    FnameExtension:=ExtractFileExt(OpenDialog1.Filename);
    Reg:=TRegistry.Create;
    try
      Reg.RootKey := HKEY_CLASSES_ROOT;
      if Reg.OpenKey(FnameExtension, False) then
      begin
        Edit1.Text:=Reg.ReadString('');
        Reg.CloseKey;
      end;
    finally
      Reg.Free;
    end;
  end;
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
Tvigep earned 60 total points
ID: 8055939
As an addition: did a bit of research in the registry, and it's easier than I thought at first. Don'ty use the first piece of code, but the snippet below should give you what you want:

(For example, if you choose a .exe file it says Application, if you choose a .bmp it says Bitmap Image, etc.)

Stef

Uses Registry;

procedure TForm1.Button1Click(Sender: TObject);
var FnameExtension:string;
    Desc1,Desc2:string;
    Reg:TRegistry;
begin
  If OpenDialog1.Execute then
  begin
    FnameExtension:=ExtractFileExt(OpenDialog1.Filename);
    Reg:=TRegistry.Create;
    try
      Reg.RootKey := HKEY_CLASSES_ROOT;
      if Reg.OpenKey(FnameExtension, False) then
      begin
        Desc1:=Reg.ReadString('');
        Reg.CloseKey;
      end;
      if Reg.OpenKey(Desc1, False) then
      begin
        Desc2:=Reg.ReadString('');
        Reg.CloseKey;
      end;
      If Desc2='' then
        Edit1.Text:=Desc1
      else
        Edit1.Text:=Desc2;
    finally
      Reg.Free;
    end;
  end;
end;
0
 

Author Comment

by:Steve2000
ID: 8056458
This code works great, but the only thing I want to know now is how to show the 'description' from a exe-file.

example:
http://www.winzip.com/downau81.cgi?winzip81.exe
The description of this file is: winzip81
(it's not winzip81.exe  -  .exe)

The description of FSRaid.exe = 'Fluid Studios Software RAID Toolkit'
0
 
LVL 2

Expert Comment

by:Tvigep
ID: 8056513
OK. Let's make sure we are talking about the same information then: let's use Notepad.exe as example. In Notepad.exe there is extra fileinformation, which gives the Company Name, Product Name, Product Version and whatever else the developers have put in there. Is that the information you're after then? For Notepad, to stick with an example we both have, the Product Version is 5.00.2140.1 (if you're on Win2K like me), and Company Name is Microsoft Corporation.

This info is accessible, but a bit more difficult. I have some code someweher lying around that get's this stuff, and there are a number of components around that also do this. BTW, which OS are you developing for?

0
 

Author Comment

by:Steve2000
ID: 8056554
I use WinXP

Yes, it's that what i mean. On the Tab 'Version':

(notepad.exe)
Product Version: 5.1.2600.0
Description (I translate it, maybe another name): Notepad
Copyright: © Microsoft Corporation
0
 
LVL 2

Expert Comment

by:Tvigep
ID: 8057601
Steve,

I used to have some code to do that. There is some WinAPI stuff to get the File Information that is stored inside executable files out of it. Unfortunately I can't find my code anywhere (it might not have been backed up). But a search on Google revealed an article here on EE :http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20358211.html
This isn't exaqctly what you want, but if you search the help you'll find more about it.

HTH,
Stef
0
 

Author Comment

by:Steve2000
ID: 8060547
:) I need only the description
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question