PC Review


Reply
Thread Tools Rate Thread

Search for files with specific extension

 
 
Merrit
Guest
Posts: n/a
 
      14th Jun 2005
Hi there,

I'm looking for a pretty easy way to search a folder for all contained
files with a specific extension and show the filenames in a listbox or
sth similar.

How can do that without using an OpenFileDialog?

Cheers,
Merrit
 
Reply With Quote
 
 
 
 
Arun
Guest
Posts: n/a
 
      14th Jun 2005
You can try to PInvoke FindFirstFile and FindNextFile to achieve this.

[DllImport("kernel32", CharSet=CharSet.Unicode)]
public static extern IntPtr FindFirstFile(string lpFileName, out
WIN32_FIND_DATA lpFindFileData);

[DllImport("kernel32", CharSet=CharSet.Unicode)]
public static extern bool FindNextFile(IntPtr hFindFile, out
WIN32_FIND_DATA lpFindFileData);

Hope this helps,
Cheers,
Arun.
www.innasite.com

 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      14th Jun 2005
System.IO.Directory.GetFiles("somefolder", "*.ext")

Returns an array of strings with the full paths of matching files in the
specified folder.

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

"Merrit" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi there,
>
> I'm looking for a pretty easy way to search a folder for all contained
> files with a specific extension and show the filenames in a listbox or sth
> similar.
>
> How can do that without using an OpenFileDialog?
>
> Cheers,
> Merrit



 
Reply With Quote
 
Merrit
Guest
Posts: n/a
 
      14th Jun 2005
Peter Foot [MVP] wrote:
> System.IO.Directory.GetFiles("somefolder", "*.ext")
>
> Returns an array of strings with the full paths of matching files in the
> specified folder.
>
> Peter
>

Thanks a lot Peter. This solution was much easier and worked perfectly well.

Cheers,
Merrit
 
Reply With Quote
 
Cyrille37
Guest
Posts: n/a
 
      21st Jun 2005
Peter Foot [MVP] a écrit :
> System.IO.Directory.GetFiles("somefolder", "*.ext")


And how to get them sorted by Date or by Size ?

thanx.
 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      21st Jun 2005
You'll have to sort them, using what you learned in your programming classes
in college...

Paul T.

"Cyrille37" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
Peter Foot [MVP] a écrit :
> System.IO.Directory.GetFiles("somefolder", "*.ext")


And how to get them sorted by Date or by Size ?

thanx.


 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      21st Jun 2005
LOL! Nevertheless, it could be done without knowing about "Binary sort",
"Bubble sort", "Shell sort" or something

Here is example how to sort files by its size:

private class SizeSorter : IComparer
{
int IComparer.Compare(object a, object b)
{
FileInfo afi = new FileInfo(a as string);
FileInfo bfi = new FileInfo(b as string);
return afi.Length.CompareTo(bfi.Length);
}
}


....

string [] f = Directory.GetFiles("currentdir", "*.*");
ArrayList al = new ArrayList(f);
al.Sort(new SizeSorter());

"al" will contain the sorted files.

--
Sergey Bogdanov
http://www.sergeybogdanov.com


Paul G. Tobey [eMVP] wrote:
> You'll have to sort them, using what you learned in your programming classes
> in college...
>
> Paul T.
>
> "Cyrille37" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> Peter Foot [MVP] a écrit :
>
>>System.IO.Directory.GetFiles("somefolder", "*.ext")

>
>
> And how to get them sorted by Date or by Size ?
>
> thanx.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for a specific file's extension 2007-User Microsoft Excel Programming 7 10th Sep 2006 05:27 AM
Tool for deleting all files except specific file extension? laterna@magic.ms Freeware 12 12th Jun 2006 09:33 AM
Hide All Files of Specific Extension =?Utf-8?B?U0o=?= Windows XP General 6 8th Nov 2004 11:56 AM
MSIE requires specific file extension of XML files with XSL styles =?Utf-8?B?UmVuw6kgQsO4amUgTmllbHNlbg==?= Windows XP Internet Explorer 0 18th Jun 2004 01:29 PM
DELETING FILES FROM A FOLDER WITH SPECIFIC EXTENSION R v Deursen Microsoft Excel Programming 1 28th May 2004 03:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:38 PM.