?
Solved

How to recognize file extension?

Posted on 2006-06-02
5
Medium Priority
?
172 Views
Last Modified: 2010-04-05
Is there any code to recognize, that a file has certain extension? For example this code would search through a folder and any file in it with *.exe extension would be counted or somewhat else.
0
Comment
Question by:JackKuti
  • 2
  • 2
5 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 16815166
I don't exactly understand the problem, but yes, findfirst/findnext with *.exe will get all files/directories that have an extension of "exe" (you can eliminate directories by putin a -faDirectory in the flags of findfirst.
also, extractfileext from sysutils get's you the extension in case you already have some filename.
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 500 total points
ID: 16815251
1. If you want to get an extention from a filename use ExtractFileExt funtion.
2. If you want to search for specific pattern (as ciuly said) use the following code.

var
  sr: TSearchRec;
  path : string;
begin
  path := 'c:\*.exe';
  if FindFirst(Path, faAnyFile, sr) = 0 then
  begin
    repeat
      if (sr.Attr and faDirectory) <> faDirectory then
      begin
        Memo1.Lines.Add(sr.Name)
      end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end
end;
0
 
LVL 28

Expert Comment

by:2266180
ID: 16817210
hm...
since the only difference between atul_parmar's solution and mine was that he also gave some source code, the correct way to go would have been a point-split. I am not saying that you should modify the status of this question (leave it, not a big deal), just to be more "carefull" in the future. I had cases when spent quite some time on getting good source and someone just copied my source and made an "imrpovement" (in the user interface) and he got the points. such cases are frustrating. this one was a few seconds ":job" so there is no problem from my part, but as I said: in future cases pay more attention at all solutions and try to give a fair outcome to the issue.

peace :)
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16817297
Coool man. its all about presentation.

I never fix an issue for points. If it's money I ofcourse.

Debgging and fixing is my passion.


0
 

Author Comment

by:JackKuti
ID: 16818924
I´ll be more careful next time...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

809 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