R
Rich P
I found a nice LinQ function for GetFiles with multiple search patters
(multiple file types -- *.jpg, *.bmp, *.gif). This seems to work nicely
except that my list of files has an alphabetical ordering like
a1.jpg
a2.jpg
a1.bmp
a2.bmp
b1.jpg
b2.jpg
b1.bmp
b2.bmp
...
and the routine is listing/sorting all the .jpg's first and then the
.bmps, .gifs.
a1.jpg
a2.jpg
b1.jpg
b2.jpg
a1.bmp
a2.bmp
b1.bmp
b2.bmp
In windows explorer the files are listed/sorted by filename
alphabetically as desired.
a1.bmp
a1.jpg
a2.bmp
a2.jpg
b1.bmp
b1.jpg
b2.bmp
b2.jpg
...
Is there a way to sort this list the same as Windows Explorer? Or --
this doesn't have to be a List by LinQ. Using the FileSystem I can add
all the search patterns inline and it sorts like Windows Explorer, but I
was advised that Directory.GetFiles is more efficient. Any suggestions
appreciated what would be the best way to GetFiles and sort them like
Windows Explorer.
//here is the LinQ GetFiles routine I found on the net
public List<string> GetFiles(string dir, List<string> patterns)
{
List<string> matches = new List<string>();
//loop thorugh all extensions provided
foreach (string pattern in patterns)
{
//use LINQ to get each file with the soecified file type
var matchingFiles = from file in Directory.GetFiles(dir,
pattern,SearchOption.AllDirectories)
select file;
//now add all files to our list
matches.AddRange(matchingFiles);
}
return matches;
}
//here is how I call it
private void btnSlideShow_Click(object sender, EventArgs e)
{
List<string> Patrns = new List<string>();
Patrns.Add("*.jpg");
Patrns.Add("*.bmp");
Patrns.Add("*.gif");
List<string> fil = new List<string>(GetFiles(lblCurDir.Text,Patrns));
foreach (string str1 in fil)
Console.WriteLine(str1);
}
Thanks
Rich
(multiple file types -- *.jpg, *.bmp, *.gif). This seems to work nicely
except that my list of files has an alphabetical ordering like
a1.jpg
a2.jpg
a1.bmp
a2.bmp
b1.jpg
b2.jpg
b1.bmp
b2.bmp
...
and the routine is listing/sorting all the .jpg's first and then the
.bmps, .gifs.
a1.jpg
a2.jpg
b1.jpg
b2.jpg
a1.bmp
a2.bmp
b1.bmp
b2.bmp
In windows explorer the files are listed/sorted by filename
alphabetically as desired.
a1.bmp
a1.jpg
a2.bmp
a2.jpg
b1.bmp
b1.jpg
b2.bmp
b2.jpg
...
Is there a way to sort this list the same as Windows Explorer? Or --
this doesn't have to be a List by LinQ. Using the FileSystem I can add
all the search patterns inline and it sorts like Windows Explorer, but I
was advised that Directory.GetFiles is more efficient. Any suggestions
appreciated what would be the best way to GetFiles and sort them like
Windows Explorer.
//here is the LinQ GetFiles routine I found on the net
public List<string> GetFiles(string dir, List<string> patterns)
{
List<string> matches = new List<string>();
//loop thorugh all extensions provided
foreach (string pattern in patterns)
{
//use LINQ to get each file with the soecified file type
var matchingFiles = from file in Directory.GetFiles(dir,
pattern,SearchOption.AllDirectories)
select file;
//now add all files to our list
matches.AddRange(matchingFiles);
}
return matches;
}
//here is how I call it
private void btnSlideShow_Click(object sender, EventArgs e)
{
List<string> Patrns = new List<string>();
Patrns.Add("*.jpg");
Patrns.Add("*.bmp");
Patrns.Add("*.gif");
List<string> fil = new List<string>(GetFiles(lblCurDir.Text,Patrns));
foreach (string str1 in fil)
Console.WriteLine(str1);
}
Thanks
Rich