Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to check if extensions follows up in a list?

How to check if extensions follows up in a list?

Scheduled Pinned Locked Moved C#
helptutorialquestion
19 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Goobashi

    So you want your program to switch between jpg and tif for every other file while incrementing the file name?

    M Offline
    M Offline
    Matjaz xyz
    wrote on last edited by
    #4

    ummm not incrementing. let me rewrite... (ps: sorry for my bad english) i select a folder. get files from that folder to and arraylist. go with "for" loop through items in that arralist and check extensions (Path.GetExtension). Well... i would go like that. The filenames are incremental... (8 digits type - 00000001 etc) but i really dont have an idea how to put everything in the code. Was trying with this but... One of the ideas was to get extension. if its "tif" then increment int TIFS and if its an JPG, stop counting tifs and add +1 to jpg - then check if the Integer TIFS and JPGS match.. bah... i'm so lost.

    Regards, Matjaž

    1 Reply Last reply
    0
    • M Matjaz xyz

      I've been brainstorming with this for a long time... and havent figured it out yet. I'm just asking for a tip to point me in the right direction... because im going in circles. The problem i have is this: Example folder contains files .jpg and .tif. I want to check them if they follow up correctly. So... this is an example of an OK folder: Example Folder> -1.jpg -2.tif -3.jpg -4.tif -5.jpg -6.jpg -7.tif -8.tif -9.jpg -10.tif You can see, that the files go - 1-1 or 2-2 (maybe also 3-3) in extension. this is when an error would occcur: Example Folder> -1.jpg -2.tif -3.jpg -4.jpg -5.tif -6.jpg -7.tif -8.jpg the extensions dont follow up. the order of the next extension is not the same. Any idea? Please?

      Regards, Matjaž

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #5

      Do you mean this? If file 1 and 2 are jpg, then 3 and 4 must be tif. That is: 2-2 if 5 is jpg, then 6 must be tif. That is 1-1. In short, number of consecutive jpf files must be equal to number of consecutive tif files. And these must be together. And if the order is not like the one above, then show error.

      Happy Holi[^] जय हिंद

      M 1 Reply Last reply
      0
      • M Matjaz xyz

        I've been brainstorming with this for a long time... and havent figured it out yet. I'm just asking for a tip to point me in the right direction... because im going in circles. The problem i have is this: Example folder contains files .jpg and .tif. I want to check them if they follow up correctly. So... this is an example of an OK folder: Example Folder> -1.jpg -2.tif -3.jpg -4.tif -5.jpg -6.jpg -7.tif -8.tif -9.jpg -10.tif You can see, that the files go - 1-1 or 2-2 (maybe also 3-3) in extension. this is when an error would occcur: Example Folder> -1.jpg -2.tif -3.jpg -4.jpg -5.tif -6.jpg -7.tif -8.jpg the extensions dont follow up. the order of the next extension is not the same. Any idea? Please?

        Regards, Matjaž

        X Offline
        X Offline
        Xmen Real
        wrote on last edited by
        #6

        If its about Windows Explorer than I think its not possible. The sorting is simple as its string... Why error occur, if you check the extension...or I might not get your question

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        M 1 Reply Last reply
        0
        • D dan sh

          Do you mean this? If file 1 and 2 are jpg, then 3 and 4 must be tif. That is: 2-2 if 5 is jpg, then 6 must be tif. That is 1-1. In short, number of consecutive jpf files must be equal to number of consecutive tif files. And these must be together. And if the order is not like the one above, then show error.

          Happy Holi[^] जय हिंद

          M Offline
          M Offline
          Matjaz xyz
          wrote on last edited by
          #7

          Yes. That's right.

          Regards, Matjaž

          D L 2 Replies Last reply
          0
          • X Xmen Real

            If its about Windows Explorer than I think its not possible. The sorting is simple as its string... Why error occur, if you check the extension...or I might not get your question

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

            M Offline
            M Offline
            Matjaz xyz
            wrote on last edited by
            #8

            It doesnt concern explorer. Basicly, the intention of this application would be to check if JPG files have their duplicate TIF files. If it would be just 1-1, then i could do it... but i cant figure this one out. And what i ment by an error was to put as an output - in which folder the files dont match.

            Regards, Matjaž

            X 1 Reply Last reply
            0
            • M Matjaz xyz

              Yes. That's right.

              Regards, Matjaž

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #9

              AFAIK you just need to set up some loops wisely. Here is a bit of quick and dirty approach I could think of:

              List s = new List ();
              s.Add("jpg");
              s.Add("tif");
              s.Add("jpg");
              s.Add("tif");
              s.Add("jpg");
              s.Add("jpg");
              s.Add("tif");
              s.Add("tif");
              s.Add("jpg");
              s.Add("tif");

                  bool breakFor = false;
                  int togetherCount = 1;
                  for (int i = 1;i < s.Count -1;i++) {
                    
                    if (s\[i\] == s\[i - 1\]) {
                      togetherCount++;
                      continue;
                    }
                    else {
                      int count = 0;
                      while (count < togetherCount) {
                        if (!(s\[i + 1\] == s\[i + count\])) {
                          if (togetherCount > 1) {
                            MessageBox.Show("error");
                            breakFor = true;
                            break;
                          }
                        }
                        count++;
                      }
                      if (breakFor) {
                        break;
                      }
                      else {
                        i = i + togetherCount;
                        togetherCount = 1;
                      }
                    }
                  }
              

              It might not be correct but good to start off I guess.

              Happy Holi[^] जय हिंद

              M 2 Replies Last reply
              0
              • M Matjaz xyz

                It doesnt concern explorer. Basicly, the intention of this application would be to check if JPG files have their duplicate TIF files. If it would be just 1-1, then i could do it... but i cant figure this one out. And what i ment by an error was to put as an output - in which folder the files dont match.

                Regards, Matjaž

                X Offline
                X Offline
                Xmen Real
                wrote on last edited by
                #10

                its simple then... try this

                    bool Test(string dirPath)
                    {
                        string\[\] filePaths = Directory.GetFiles(dirPath, "\*.jpg");
                        for (int a = 0; a < filePaths.Length; a++)
                        {
                            if (!File.Exists(Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePaths\[a\]) + ".tif")))
                                return false;
                        }
                        return true;
                    }
                

                TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                M 1 Reply Last reply
                0
                • X Xmen Real

                  its simple then... try this

                      bool Test(string dirPath)
                      {
                          string\[\] filePaths = Directory.GetFiles(dirPath, "\*.jpg");
                          for (int a = 0; a < filePaths.Length; a++)
                          {
                              if (!File.Exists(Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePaths\[a\]) + ".tif")))
                                  return false;
                          }
                          return true;
                      }
                  

                  TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                  M Offline
                  M Offline
                  Matjaz xyz
                  wrote on last edited by
                  #11

                  Umm not duplicates :/ sorry... just... the follow up files. 1.jpg has his own tif, but with a different name. example... 3.tif, because there is another 2.jpg before.

                  Regards, Matjaž

                  D X L 3 Replies Last reply
                  0
                  • M Matjaz xyz

                    Umm not duplicates :/ sorry... just... the follow up files. 1.jpg has his own tif, but with a different name. example... 3.tif, because there is another 2.jpg before.

                    Regards, Matjaž

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #12

                    In that case, just get the count of files with JPG and count of files with TIF and they must be equal. Dump the code I had posted. Edit: There is a lot of misunderstanding going on in this post. :doh:

                    Happy Holi[^] जय हिंद

                    M 1 Reply Last reply
                    0
                    • D dan sh

                      In that case, just get the count of files with JPG and count of files with TIF and they must be equal. Dump the code I had posted. Edit: There is a lot of misunderstanding going on in this post. :doh:

                      Happy Holi[^] जय हिंद

                      M Offline
                      M Offline
                      Matjaz xyz
                      wrote on last edited by
                      #13

                      I already thought of that - but it is definitly a no-go. Why? Well, maybe there are some files which dont have their tifs, but some tiffs dont have their jpgs - and the count may match.

                      Regards, Matjaž

                      1 Reply Last reply
                      0
                      • M Matjaz xyz

                        Umm not duplicates :/ sorry... just... the follow up files. 1.jpg has his own tif, but with a different name. example... 3.tif, because there is another 2.jpg before.

                        Regards, Matjaž

                        X Offline
                        X Offline
                        Xmen Real
                        wrote on last edited by
                        #14

                        aha I got ya now. The thing you want called Stack. Last In Last Out.

                        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                        1 Reply Last reply
                        0
                        • D dan sh

                          AFAIK you just need to set up some loops wisely. Here is a bit of quick and dirty approach I could think of:

                          List s = new List ();
                          s.Add("jpg");
                          s.Add("tif");
                          s.Add("jpg");
                          s.Add("tif");
                          s.Add("jpg");
                          s.Add("jpg");
                          s.Add("tif");
                          s.Add("tif");
                          s.Add("jpg");
                          s.Add("tif");

                              bool breakFor = false;
                              int togetherCount = 1;
                              for (int i = 1;i < s.Count -1;i++) {
                                
                                if (s\[i\] == s\[i - 1\]) {
                                  togetherCount++;
                                  continue;
                                }
                                else {
                                  int count = 0;
                                  while (count < togetherCount) {
                                    if (!(s\[i + 1\] == s\[i + count\])) {
                                      if (togetherCount > 1) {
                                        MessageBox.Show("error");
                                        breakFor = true;
                                        break;
                                      }
                                    }
                                    count++;
                                  }
                                  if (breakFor) {
                                    break;
                                  }
                                  else {
                                    i = i + togetherCount;
                                    togetherCount = 1;
                                  }
                                }
                              }
                          

                          It might not be correct but good to start off I guess.

                          Happy Holi[^] जय हिंद

                          M Offline
                          M Offline
                          Matjaz xyz
                          wrote on last edited by
                          #15

                          Hmm... it sure looks like it's in the right way. Thanks for taking the time. I'll try to implent something similar and report what happend. Thank you

                          Regards, Matjaž

                          1 Reply Last reply
                          0
                          • D dan sh

                            AFAIK you just need to set up some loops wisely. Here is a bit of quick and dirty approach I could think of:

                            List s = new List ();
                            s.Add("jpg");
                            s.Add("tif");
                            s.Add("jpg");
                            s.Add("tif");
                            s.Add("jpg");
                            s.Add("jpg");
                            s.Add("tif");
                            s.Add("tif");
                            s.Add("jpg");
                            s.Add("tif");

                                bool breakFor = false;
                                int togetherCount = 1;
                                for (int i = 1;i < s.Count -1;i++) {
                                  
                                  if (s\[i\] == s\[i - 1\]) {
                                    togetherCount++;
                                    continue;
                                  }
                                  else {
                                    int count = 0;
                                    while (count < togetherCount) {
                                      if (!(s\[i + 1\] == s\[i + count\])) {
                                        if (togetherCount > 1) {
                                          MessageBox.Show("error");
                                          breakFor = true;
                                          break;
                                        }
                                      }
                                      count++;
                                    }
                                    if (breakFor) {
                                      break;
                                    }
                                    else {
                                      i = i + togetherCount;
                                      togetherCount = 1;
                                    }
                                  }
                                }
                            

                            It might not be correct but good to start off I guess.

                            Happy Holi[^] जय हिंद

                            M Offline
                            M Offline
                            Matjaz xyz
                            wrote on last edited by
                            #16

                            Somehow it seems i didnt implent this correctly... or it doesnt work right (like you said, it could and could not work)... aah :/

                            if (fbd1.ShowDialog() != DialogResult.Cancel)
                            {
                            if (checkBox1.Checked == true)
                            DIRI.Items.AddRange(Directory.GetDirectories(fbd1.SelectedPath, "*.*", SearchOption.AllDirectories));
                            else
                            DIRI.Items.AddRange(Directory.GetDirectories(fbd1.SelectedPath, "*.*", SearchOption.TopDirectoryOnly));

                                        for (int i = 0; i < DIRI.Items.Count; i++)
                                        {
                                            ArrayList DATOTEKE = new ArrayList();
                                            DATOTEKE.AddRange(Directory.GetFiles(DIRI.Items\[i\].ToString().ToLower()));
                            
                                            ArrayList KONCNICE = new ArrayList();
                            
                                            for (int bo = 0; bo < DATOTEKE.Count; bo++)
                                            {
                                                KONCNICE.Add(Path.GetExtension(DATOTEKE\[i\].ToString()));
                                            }
                            
                            
                            
                                            bool breakFor = false;
                                            int togetherCount = 1;
                                            for (int j = 1; j < KONCNICE.Count - 1; i++)
                                            {
                                                if (KONCNICE\[j\] == KONCNICE\[j - 1\])
                                                {
                                                    togetherCount++;
                                                    continue;
                                                }
                                                else
                                                {
                                                    int count = 0;
                                                    while (count < togetherCount)
                                                    {
                                                        if (!(KONCNICE\[j + 1\] == KONCNICE\[j + count\]))
                                                        {
                                                            if (togetherCount > 1)
                                                            {
                                                                //if (listBox1.FindStringExact(DIRI.Items\[i\].ToString()) > 0)
                                                                    listBox1.Items.Add(DIRI.Items\[i\].ToString());
                                                                breakFor = true;
                                                                break;
                                                            }
                                                        }
                                                        count++;
                                                    }
                                                    if (breakFor)
                                                    {
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        j = j + togetherCount;
                            
                            D 1 Reply Last reply
                            0
                            • M Matjaz xyz

                              Somehow it seems i didnt implent this correctly... or it doesnt work right (like you said, it could and could not work)... aah :/

                              if (fbd1.ShowDialog() != DialogResult.Cancel)
                              {
                              if (checkBox1.Checked == true)
                              DIRI.Items.AddRange(Directory.GetDirectories(fbd1.SelectedPath, "*.*", SearchOption.AllDirectories));
                              else
                              DIRI.Items.AddRange(Directory.GetDirectories(fbd1.SelectedPath, "*.*", SearchOption.TopDirectoryOnly));

                                          for (int i = 0; i < DIRI.Items.Count; i++)
                                          {
                                              ArrayList DATOTEKE = new ArrayList();
                                              DATOTEKE.AddRange(Directory.GetFiles(DIRI.Items\[i\].ToString().ToLower()));
                              
                                              ArrayList KONCNICE = new ArrayList();
                              
                                              for (int bo = 0; bo < DATOTEKE.Count; bo++)
                                              {
                                                  KONCNICE.Add(Path.GetExtension(DATOTEKE\[i\].ToString()));
                                              }
                              
                              
                              
                                              bool breakFor = false;
                                              int togetherCount = 1;
                                              for (int j = 1; j < KONCNICE.Count - 1; i++)
                                              {
                                                  if (KONCNICE\[j\] == KONCNICE\[j - 1\])
                                                  {
                                                      togetherCount++;
                                                      continue;
                                                  }
                                                  else
                                                  {
                                                      int count = 0;
                                                      while (count < togetherCount)
                                                      {
                                                          if (!(KONCNICE\[j + 1\] == KONCNICE\[j + count\]))
                                                          {
                                                              if (togetherCount > 1)
                                                              {
                                                                  //if (listBox1.FindStringExact(DIRI.Items\[i\].ToString()) > 0)
                                                                      listBox1.Items.Add(DIRI.Items\[i\].ToString());
                                                                  breakFor = true;
                                                                  break;
                                                              }
                                                          }
                                                          count++;
                                                      }
                                                      if (breakFor)
                                                      {
                                                          break;
                                                      }
                                                      else
                                                      {
                                                          j = j + togetherCount;
                              
                              D Offline
                              D Offline
                              dan sh
                              wrote on last edited by
                              #17

                              I would say, debug the code and find where you are wrong. Get hold of the logic and you will be done.

                              Matjaž Grahek wrote:

                              if (!(KONCNICE[j + 1] == KONCNICE[j + count]))

                              One thing I can figure out is you need to remoe this + 1. I have not debugged the code just read it so I may go wrong.

                              Happy Holi[^] जय हिंद

                              1 Reply Last reply
                              0
                              • M Matjaz xyz

                                Yes. That's right.

                                Regards, Matjaž

                                L Offline
                                L Offline
                                Luc Pattyn
                                wrote on last edited by
                                #18

                                In today's pseudo-language that would be:

                                filelist=getAllFilenames()
                                filelist.Sort
                                diff=0
                                foreach(file in filelist) {
                                if (jpg) diff++
                                else diff--
                                if (diff<-1 or diff>1) error
                                }

                                Two remarks: 1. to get a natural sort order for the file names, same as Windows Explorer does, you would need to use Explorer's code, i.e. use P/Invoke and the prototype:

                                	\[DllImport("shlwapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)\]
                                	private static extern int StrCmpLogicalW(string s1, string s2);
                                

                                Of course if the name part is just a number, you could use int.Parse and sort based on the outcome. 2. I cannot imagine where and how your requirement could ever have a useful application. :)

                                Luc Pattyn [Forum Guidelines] [My Articles]


                                - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                                1 Reply Last reply
                                0
                                • M Matjaz xyz

                                  Umm not duplicates :/ sorry... just... the follow up files. 1.jpg has his own tif, but with a different name. example... 3.tif, because there is another 2.jpg before.

                                  Regards, Matjaž

                                  L Offline
                                  L Offline
                                  Luc Pattyn
                                  wrote on last edited by
                                  #19

                                  Matjaž Grahek wrote:

                                  1.jpg has his own tif, but with a different name

                                  that is plain stupid. Extensions exist so files that belong together can share the name part of a filename. Use it to your advantage rather than strugging with some code to fix the mistake. :)

                                  Luc Pattyn [Forum Guidelines] [My Articles]


                                  - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups