R
Rich P
Actually, I have two questions.
I wrote a program which displays images in a slideshow type manner. The
image files are .jpg and .bmp and .gif images. They are stored in a
variety of subfolders under a parent folder. There are about 14,000
image files in these subfolders. I retrieve each image file as follows:
List<string> myList = new List<string>();
foreach (string str1 in My.Computer.FileSystem.GetFiles("C:\\1A",
FileIO.SearchOption.SearchAllSubDirectories,
"*.jpg", "*.bmp", "*.gif"))
{
myList.Add(str1);
}
Currently, I read all the files into this list object and then display
each image for 1 second and then display the next image, ... in a loop
(it is basically a search for something by seeing it program) . The
image files are named in the following manner:
aaa1.jpg
aaa2.jpg
aaa3.jpg
...
aaa100.jpg
abcbbb1.jpg
abcbbb2.jpg
...
abcbbb77.jpg
cccttttt1.jpg
cccttttt2.jpg
...
cccttttt142.jpg
ddd1.bmp
ddd2.jpg
ddd3.gif
ddd4.jpg
...
ddd95.jpg
...
and the subfolders are named fldA, fldB, fldC, ... fldZ where image
files that begin with "a" will be stored in fldA, image files that begin
with "b" will be stored in fldB, ...
Basically, I have groups of image files where a group has the same
beginning text in the filename (alpha chars) and then followed by a
numeric char (incremented as aaa1, aaa2, aaa3, ...aaa100). So group aaa
may have 100 image files that begin with "aaa" before encountering a
numeric char, group "abcbbb" may have 77 files, ...
What I want to do is this: when a group of images begins displaying -
group "aaa" for example - I want to display the count of files in that
group while that group of images is being displayed. I would have a
label reading "Count of 'aaa' is 100". Then when the next group of
images is displayed the label would change to "Count of 'abcbbb' is 77"
and so on.
I could like pick the max count for a given group or I could do a "Group
By" type query on the current group of images being displayed. Then -
for each group I would have to search the filename for the point at
which the char becomes numeric and then find the max number value or do
the "Group By" thing based on the alpha portion of the filenames.
in pseudocode I would have something like this:
class myGroup
{
//alpha part of filename in the group
//count of files in this group
string GroupName;
int GroupCount;
}
string s1, s2;
int Lcount = 0;
//store just the group name in another list object
List<myGroup> myGroups = new List<myGroup>();
myGroups = LinQ magic to get group - parsing out the number part of the
group filenames from the 14,000 files in myList -- which may be only 200
individual groups of image files
for (int i = 0; i < myGroups.Count, i++)
{
//now get the list of filenames for this group
//more LinQ magic to get just the "aaa's" then the "abcbbb's", then
the "bbb's", ...
List<string> newFileList = new List<string>();
//get files from myList where the alpha portion of the filenames
matches the current myGroups.GroupName
LabelCount.Text = myGroups.GroupCount.ToString() + " files in " +
myGroups.GroupName.ToString();
for (int j = 0; j < newfileList; j++)
{
//display image
}
}
Question 1: Could LinQ do this? If yes - may I ask for an example how?
Question 2: would it be more efficient to read the subfolders
individually? Where I would just loop through each subfolder.
Like subfolder fldA may store 1000 image files, fldM may have 3000
files, fldQ may have only 50 image files. Right now I am just reading
everything into memory - all 14,000 filenames. would there be any
performance/efficiency difference between reading everything in one
chunk or reading the subfolders individually?
Rich
I wrote a program which displays images in a slideshow type manner. The
image files are .jpg and .bmp and .gif images. They are stored in a
variety of subfolders under a parent folder. There are about 14,000
image files in these subfolders. I retrieve each image file as follows:
List<string> myList = new List<string>();
foreach (string str1 in My.Computer.FileSystem.GetFiles("C:\\1A",
FileIO.SearchOption.SearchAllSubDirectories,
"*.jpg", "*.bmp", "*.gif"))
{
myList.Add(str1);
}
Currently, I read all the files into this list object and then display
each image for 1 second and then display the next image, ... in a loop
(it is basically a search for something by seeing it program) . The
image files are named in the following manner:
aaa1.jpg
aaa2.jpg
aaa3.jpg
...
aaa100.jpg
abcbbb1.jpg
abcbbb2.jpg
...
abcbbb77.jpg
cccttttt1.jpg
cccttttt2.jpg
...
cccttttt142.jpg
ddd1.bmp
ddd2.jpg
ddd3.gif
ddd4.jpg
...
ddd95.jpg
...
and the subfolders are named fldA, fldB, fldC, ... fldZ where image
files that begin with "a" will be stored in fldA, image files that begin
with "b" will be stored in fldB, ...
Basically, I have groups of image files where a group has the same
beginning text in the filename (alpha chars) and then followed by a
numeric char (incremented as aaa1, aaa2, aaa3, ...aaa100). So group aaa
may have 100 image files that begin with "aaa" before encountering a
numeric char, group "abcbbb" may have 77 files, ...
What I want to do is this: when a group of images begins displaying -
group "aaa" for example - I want to display the count of files in that
group while that group of images is being displayed. I would have a
label reading "Count of 'aaa' is 100". Then when the next group of
images is displayed the label would change to "Count of 'abcbbb' is 77"
and so on.
I could like pick the max count for a given group or I could do a "Group
By" type query on the current group of images being displayed. Then -
for each group I would have to search the filename for the point at
which the char becomes numeric and then find the max number value or do
the "Group By" thing based on the alpha portion of the filenames.
in pseudocode I would have something like this:
class myGroup
{
//alpha part of filename in the group
//count of files in this group
string GroupName;
int GroupCount;
}
string s1, s2;
int Lcount = 0;
//store just the group name in another list object
List<myGroup> myGroups = new List<myGroup>();
myGroups = LinQ magic to get group - parsing out the number part of the
group filenames from the 14,000 files in myList -- which may be only 200
individual groups of image files
for (int i = 0; i < myGroups.Count, i++)
{
//now get the list of filenames for this group
//more LinQ magic to get just the "aaa's" then the "abcbbb's", then
the "bbb's", ...
List<string> newFileList = new List<string>();
//get files from myList where the alpha portion of the filenames
matches the current myGroups.GroupName
LabelCount.Text = myGroups.GroupCount.ToString() + " files in " +
myGroups.GroupName.ToString();
for (int j = 0; j < newfileList; j++)
{
//display image
}
}
Question 1: Could LinQ do this? If yes - may I ask for an example how?
Question 2: would it be more efficient to read the subfolders
individually? Where I would just loop through each subfolder.
Like subfolder fldA may store 1000 image files, fldM may have 3000
files, fldQ may have only 50 image files. Right now I am just reading
everything into memory - all 14,000 filenames. would there be any
performance/efficiency difference between reading everything in one
chunk or reading the subfolders individually?
Rich