Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the end I will finish this code. But I want to check how you will make it?
On the moment, i am stuck and I need to refresh myself. A pause.
The Problem enunciate like this:
I have many images that contain -pre and -fullview in the end of their names.
Some are the same image, some are diferent...it's a mess.
The -pre images are at low rezolution, but -fullview are max rezolution.
My program must sort -pre from -ful (i did it already with 2 lists).
then, erase -pre, IF image is the SAME name for -pre and -full.
Keep in mind there are also unique images that have pre but not full. Also, only -full images that dont have -pre to be clear out.
How would you deal with this ... shingle ?
Thank you.

Aham...I looked over the stack element, but... i never worked seriously with it, so its hard for me to implement it at the moment. I mention about it, because maybe that is what i miss to do my life easier. You tell me.

What I have tried:

List<string> ImagesName = new List<string>();
ImagesName.AddRange(new string[] { "a.jpg", "a1-pre.jpg", "a1-fullview.jpg", "a2-pre.png", "a2-pre.png", "a3-fullview.jpg", "a3-fullview.jpg", "a4-fullview.jpg" });


//pre, fullview image duplicate cleaning
List<string> Duplicates = new List<string>();
string pre = "-pre.", ful = "-fullview."; bool isX = true;
string link = "", LinkWithNoPre = "", dupelink = "";
List<string> linkWithPre = new List<string>();
List<string> linkWithFul = new List<string>();
for (int i = 0; i < ImagesName.Count; i++)
{
    if (ImagesName[i].Contains(pre)) linkWithPre.Add(ImagesName[i]);
}
for (int i = 0; i < ImagesName.Count; i++)
{
    if (ImagesName[i].Contains(ful)) linkWithFul.Add(ImagesName[i]);
}

for (int k = 0; k < ImagesName.Count; k++)
{
    link = ImagesName[k];
    if (link.Contains(pre))
    {
        //clears the "-pre.jpg" from name
        int hu = link.IndexOf(pre);
        LinkWithNoPre = link.Remove(hu, link.Length - hu);


        for (int i = 0; i < linkWithPre.Count; i++)
        {
            link = linkWithPre[i];
            if (link.Contains(LinkWithNoPre))
            {

            }
        }
    }
}
Posted
Updated 7-Feb-19 5:07am

So you need to remove pre files that have fullview versions.
Start by enumerating all the fullview names. For each name look to see if there is a pre version, and if so delete it. Or am I missing something?
 
Share this answer
 
Comments
_Q12_ 7-Feb-19 10:24am    
I like your solution . I was thinking a bit more complicated.
So, for each fullversion, if pre exist, delete it. Very nice.
---
And if are 2 identical in a group of 3 files (1 pre and 2 identical full) ?
I suppose 2 identical lists to compare the first with the second, and make the 3d list with the results. Oh boy.
Richard MacCutchan 7-Feb-19 10:35am    
You cannot have two files with identical names in the same folder.
_Q12_ 7-Feb-19 10:56am    
heh, thats true. :)
You could create a dictionary accepting a string as key (the filename without the -pre or -ful suffix) associated to a tuple of boolean values indicating whether the filename exists with -pre, -ful, or both suffixes.
You could then iterate through the dictionary and act accordingly.
C#
var dic = new Dictionary<string, Tuple<bool, bool>>;
// Here you populate the dictionary with file informations
foreach (string name in dic.Keys) {
  var entry = dic[name];
  if (entry.Item1 && !entry.Item2) {
    // Here the case where the file only exists with the -pre suffix
  }
  else if (!entry.Item1 && entry.Item2) {
    // Here the case where the file only exists with the -ful suffix
  }
  else if (entry.Item1 && entry.Item2) {
    // Here the case where both suffixes are present
  }
 
Share this answer
 
Comments
_Q12_ 7-Feb-19 10:27am    
i like your answer too, but its a bit advanced for me since i never worked with dictionaries. It is interesting your solution! I will give it a try.
phil.o 7-Feb-19 13:34pm    
You are welcome. Dictionaries are quite useful, and not so hard learning to use.
I really think the key to this would be to enumerate the actual files via System.IO

1. Use the base-name of the file (a, a1, a2)
2. Check and see if they exist, same with the -pre and -ful variants
3. Compare the base, pre, & full variants to see if they are the same file.
4. If they match you rules, delete what is not needed.

Now there are a couple of ways you could compare them:
1. Use system.io to get basic properties like file-size.
2. Open the files in streamreader and check the MD5 of the contents
3. Open the file and...
3a. Use system.drawing and GDI to check dimensions
-OR-
3b. Use EXIF properties to check dimensions
 
Share this answer
 
Comments
_Q12_ 7-Feb-19 11:08am    
Nice idea also ! Nice approach.
The thing is...i avoid to mention in the start, but i get those images as links actually. In the end, they will be downloaded and physically be on my hdd. But your solution can be well put in practice, After I down them all. Yes, its very nice, especially, checking for dimensions in GDI and System.IO (wich i can do); the other variants i must learn to do them (MD5 stream and Exif).
Pretty sweet.
MadMyche 7-Feb-19 11:47am    
Yea, the links throws a wrench into it; these would all require them to be local. Unless the list has more info like file-size etc.
For MD5, there is a good example at https://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900