Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Fileaccess

Posted on 2003-02-26
9
Medium Priority
?
162 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
  • 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
Industry Leaders: 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

579 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