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. The Lounge
  3. Difficult to sort

Difficult to sort

Scheduled Pinned Locked Moved The Lounge
36 Posts 17 Posters 2 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.
  • A Amarnath S

    Came across a folder having files with these names: Eighth.txt Eleventh.txt Fifth.txt First.txt Fourth.txt Ninth.txt Second.txt Seventh.txt Sixth.txt Tenth.txt Third.txt Not easy to sort :-(

    J Offline
    J Offline
    Johnny J
    wrote on last edited by
    #6

    Why? Because you only have ten fingers? ;)

    Anything that is unrelated to elephants is irrelephant
    Anonymous
    -----
    The problem with quotes on the internet is that you can never tell if they're genuine
    Winston Churchill, 1944
    -----
    I'd just like a chance to prove that money can't make me happy.
    Me, all the time

    1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      No need to: they are already sorted alphabetically!

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      A Offline
      A Offline
      Amarnath S
      wrote on last edited by
      #7

      Nah ... You know what I mean :-)

      OriginalGriffO 1 Reply Last reply
      0
      • A Amarnath S

        Nah ... You know what I mean :-)

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #8

        Easy: sort by creation date...

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        A 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Easy: sort by creation date...

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          A Offline
          A Offline
          Amarnath S
          wrote on last edited by
          #9

          For some strange / unknown reason, the creation time is the same, to the level of second. And the files are modified in different orders by different people, and we cannot use the 'Date of Modification' also.

          1 Reply Last reply
          0
          • A Amarnath S

            Came across a folder having files with these names: Eighth.txt Eleventh.txt Fifth.txt First.txt Fourth.txt Ninth.txt Second.txt Seventh.txt Sixth.txt Tenth.txt Third.txt Not easy to sort :-(

            F Offline
            F Offline
            FIorian Schneidereit
            wrote on last edited by
            #10

            I'd be a bully and rename them to 01.txt ... 11.txt, or 01st.txt to 11th.txt

            1 Reply Last reply
            0
            • Mike HankeyM Mike Hankey
              1. Select ALL 2) Delete Where's the problem? :)

              New version: WinHeist Version 2.1.0 My goal in life is to have a psychiatric disorder named after me. I'm currently unsupervised, I know it freaks me out too but the possibilities are endless.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #11

              Mike Hankey wrote:

              1. Select ALL
              2. Delete
                 
                Where's the problem? Sorted!:)

              FTFY

              PooperPig - Coming Soon

              1 Reply Last reply
              0
              • A Amarnath S

                Came across a folder having files with these names: Eighth.txt Eleventh.txt Fifth.txt First.txt Fourth.txt Ninth.txt Second.txt Seventh.txt Sixth.txt Tenth.txt Third.txt Not easy to sort :-(

                N Offline
                N Offline
                newton saber
                wrote on last edited by
                #12

                Here, I solved this with C# and Linqpad. Here are the steps: 1. Get LINQPad at http://www.linqpad.net/[^] It's a great free tool which allows you to run C# as a script 2. Copy the code below to LINQPad 3. Change the <yourPathToFiles> to the path to your files. 4. run Notice that it uses an enumeration to set the value automatically of each string ("first", "second", etc) to a numeric value. After that it adds the file names to the SortedList and then prints them out. Easy as that. If you need other FileInfo about those files, it would be very easy to add. This'll get you started. The number one thing about this is, GET LINQPAD. It is a great tool.

                void Main()
                {
                string [] allFiles = Directory.GetFiles(@"C:\","*.txt");
                SortedList allFileNames = new SortedList();
                order fileSortOrder = new order();
                foreach (string filename in allFiles)
                {
                string tempName = Path.GetFileNameWithoutExtension(filename);
                allFileNames.Add(Enum.Parse(fileSortOrder.GetType(),tempName), Path.GetFileName(filename));
                }
                for (int i=0; i< allFileNames.Count;i++)
                {
                Console.WriteLine(allFileNames.GetByIndex(i));
                }
                }

                enum order
                {
                first,
                second,
                third,
                fourth,
                fifth,
                sixth,
                seventh,
                eighth,
                ninth,
                tenth,
                eleventh
                }

                OUTPUT

                first.txt
                second.txt
                third.txt
                fourth.txt
                fifth.txt
                sixth.txt
                seventh.txt
                eighth.txt
                ninth.txt
                tenth.txt
                eleventh.txt

                realJSOPR A P 3 Replies Last reply
                0
                • N newton saber

                  Here, I solved this with C# and Linqpad. Here are the steps: 1. Get LINQPad at http://www.linqpad.net/[^] It's a great free tool which allows you to run C# as a script 2. Copy the code below to LINQPad 3. Change the <yourPathToFiles> to the path to your files. 4. run Notice that it uses an enumeration to set the value automatically of each string ("first", "second", etc) to a numeric value. After that it adds the file names to the SortedList and then prints them out. Easy as that. If you need other FileInfo about those files, it would be very easy to add. This'll get you started. The number one thing about this is, GET LINQPAD. It is a great tool.

                  void Main()
                  {
                  string [] allFiles = Directory.GetFiles(@"C:\","*.txt");
                  SortedList allFileNames = new SortedList();
                  order fileSortOrder = new order();
                  foreach (string filename in allFiles)
                  {
                  string tempName = Path.GetFileNameWithoutExtension(filename);
                  allFileNames.Add(Enum.Parse(fileSortOrder.GetType(),tempName), Path.GetFileName(filename));
                  }
                  for (int i=0; i< allFileNames.Count;i++)
                  {
                  Console.WriteLine(allFileNames.GetByIndex(i));
                  }
                  }

                  enum order
                  {
                  first,
                  second,
                  third,
                  fourth,
                  fifth,
                  sixth,
                  seventh,
                  eighth,
                  ninth,
                  tenth,
                  eleventh
                  }

                  OUTPUT

                  first.txt
                  second.txt
                  third.txt
                  fourth.txt
                  fifth.txt
                  sixth.txt
                  seventh.txt
                  eighth.txt
                  ninth.txt
                  tenth.txt
                  eleventh.txt

                  realJSOPR Offline
                  realJSOPR Offline
                  realJSOP
                  wrote on last edited by
                  #13

                  Solves for the known set, but what about twelfth.txt, thirteenth.txt, etc?

                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                  -----
                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                  -----
                  When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                  N P 2 Replies Last reply
                  0
                  • realJSOPR realJSOP

                    Solves for the known set, but what about twelfth.txt, thirteenth.txt, etc?

                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                    -----
                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                    -----
                    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                    N Offline
                    N Offline
                    newton saber
                    wrote on last edited by
                    #14

                    John Simmons / outlaw programmer wrote:

                    Solves for the known set, but what about twelfth.txt, thirteenth.txt, etc?

                    That is a great question. If the user had more of those crazy file names, he can simply add the names to the enum and it will work. You may say to that, "well, there could be hundreds of these". Yes, and for that we could use the Directory.GetFiles() and Path.GetFileNameWithoutExtension to gen a comma delimited list and save it to a file, then just copy the list to the enumeration and that part would be done too. It's a bit clunky, but it does work. :) EDIT: Oops I think I fell into a loop of thinking here. :-O Actually, when you use Directory.GetFiles and got the names, they wouldn't be sorted properly to add to the enum so we are back at the beginning challenge. The sort is all based upon the enum being in order since an enum's values are then in ascending order by default.

                    F 1 Reply Last reply
                    0
                    • N newton saber

                      John Simmons / outlaw programmer wrote:

                      Solves for the known set, but what about twelfth.txt, thirteenth.txt, etc?

                      That is a great question. If the user had more of those crazy file names, he can simply add the names to the enum and it will work. You may say to that, "well, there could be hundreds of these". Yes, and for that we could use the Directory.GetFiles() and Path.GetFileNameWithoutExtension to gen a comma delimited list and save it to a file, then just copy the list to the enumeration and that part would be done too. It's a bit clunky, but it does work. :) EDIT: Oops I think I fell into a loop of thinking here. :-O Actually, when you use Directory.GetFiles and got the names, they wouldn't be sorted properly to add to the enum so we are back at the beginning challenge. The sort is all based upon the enum being in order since an enum's values are then in ascending order by default.

                      F Offline
                      F Offline
                      Freak30
                      wrote on last edited by
                      #15

                      But then you still have the problem, that you need to sort the comma delimited list manually before you put it into the enum.

                      The good thing about pessimism is, that you are always either right or pleasently surprised.

                      N 1 Reply Last reply
                      0
                      • F Freak30

                        But then you still have the problem, that you need to sort the comma delimited list manually before you put it into the enum.

                        The good thing about pessimism is, that you are always either right or pleasently surprised.

                        N Offline
                        N Offline
                        newton saber
                        wrote on last edited by
                        #16

                        I think I was editing as you were replying. :-O Oops, you are right.

                        1 Reply Last reply
                        0
                        • N newton saber

                          Here, I solved this with C# and Linqpad. Here are the steps: 1. Get LINQPad at http://www.linqpad.net/[^] It's a great free tool which allows you to run C# as a script 2. Copy the code below to LINQPad 3. Change the <yourPathToFiles> to the path to your files. 4. run Notice that it uses an enumeration to set the value automatically of each string ("first", "second", etc) to a numeric value. After that it adds the file names to the SortedList and then prints them out. Easy as that. If you need other FileInfo about those files, it would be very easy to add. This'll get you started. The number one thing about this is, GET LINQPAD. It is a great tool.

                          void Main()
                          {
                          string [] allFiles = Directory.GetFiles(@"C:\","*.txt");
                          SortedList allFileNames = new SortedList();
                          order fileSortOrder = new order();
                          foreach (string filename in allFiles)
                          {
                          string tempName = Path.GetFileNameWithoutExtension(filename);
                          allFileNames.Add(Enum.Parse(fileSortOrder.GetType(),tempName), Path.GetFileName(filename));
                          }
                          for (int i=0; i< allFileNames.Count;i++)
                          {
                          Console.WriteLine(allFileNames.GetByIndex(i));
                          }
                          }

                          enum order
                          {
                          first,
                          second,
                          third,
                          fourth,
                          fifth,
                          sixth,
                          seventh,
                          eighth,
                          ninth,
                          tenth,
                          eleventh
                          }

                          OUTPUT

                          first.txt
                          second.txt
                          third.txt
                          fourth.txt
                          fifth.txt
                          sixth.txt
                          seventh.txt
                          eighth.txt
                          ninth.txt
                          tenth.txt
                          eleventh.txt

                          A Offline
                          A Offline
                          Amarnath S
                          wrote on last edited by
                          #17

                          Wow. I'll get LINQPad.

                          1 Reply Last reply
                          0
                          • N newton saber

                            Here, I solved this with C# and Linqpad. Here are the steps: 1. Get LINQPad at http://www.linqpad.net/[^] It's a great free tool which allows you to run C# as a script 2. Copy the code below to LINQPad 3. Change the <yourPathToFiles> to the path to your files. 4. run Notice that it uses an enumeration to set the value automatically of each string ("first", "second", etc) to a numeric value. After that it adds the file names to the SortedList and then prints them out. Easy as that. If you need other FileInfo about those files, it would be very easy to add. This'll get you started. The number one thing about this is, GET LINQPAD. It is a great tool.

                            void Main()
                            {
                            string [] allFiles = Directory.GetFiles(@"C:\","*.txt");
                            SortedList allFileNames = new SortedList();
                            order fileSortOrder = new order();
                            foreach (string filename in allFiles)
                            {
                            string tempName = Path.GetFileNameWithoutExtension(filename);
                            allFileNames.Add(Enum.Parse(fileSortOrder.GetType(),tempName), Path.GetFileName(filename));
                            }
                            for (int i=0; i< allFileNames.Count;i++)
                            {
                            Console.WriteLine(allFileNames.GetByIndex(i));
                            }
                            }

                            enum order
                            {
                            first,
                            second,
                            third,
                            fourth,
                            fifth,
                            sixth,
                            seventh,
                            eighth,
                            ninth,
                            tenth,
                            eleventh
                            }

                            OUTPUT

                            first.txt
                            second.txt
                            third.txt
                            fourth.txt
                            fifth.txt
                            sixth.txt
                            seventh.txt
                            eighth.txt
                            ninth.txt
                            tenth.txt
                            eleventh.txt

                            P Offline
                            P Offline
                            PhilLenoir
                            wrote on last edited by
                            #18

                            Trust a c#er to come up with a needlessly complex solution. Create a file: list.bat with the following content

                            echo first.txt
                            echo second.txt
                            echo third.txt
                            echo fourth.txt
                            echo fifth.txt
                            echo sixth.txt
                            echo seventh.txt
                            echo eighth.txt
                            echo ninth.txt
                            echo tenth.txt
                            echo eleventh.txt

                            QED (Quite Easily Done)! You don't even need a programmer if they create more files - just a text editor. Sorted - I'll go and help Griff make coffee now (poor old sod needs help!)

                            Life is like a s**t sandwich; the more bread you have, the less s**t you eat.

                            N 1 Reply Last reply
                            0
                            • P PhilLenoir

                              Trust a c#er to come up with a needlessly complex solution. Create a file: list.bat with the following content

                              echo first.txt
                              echo second.txt
                              echo third.txt
                              echo fourth.txt
                              echo fifth.txt
                              echo sixth.txt
                              echo seventh.txt
                              echo eighth.txt
                              echo ninth.txt
                              echo tenth.txt
                              echo eleventh.txt

                              QED (Quite Easily Done)! You don't even need a programmer if they create more files - just a text editor. Sorted - I'll go and help Griff make coffee now (poor old sod needs help!)

                              Life is like a s**t sandwich; the more bread you have, the less s**t you eat.

                              N Offline
                              N Offline
                              newton saber
                              wrote on last edited by
                              #19

                              But...I love needless complexity. My coffee makes itself with C#. :rolleyes:

                              P 1 Reply Last reply
                              0
                              • N newton saber

                                But...I love needless complexity. My coffee makes itself with C#. :rolleyes:

                                P Offline
                                P Offline
                                PhilLenoir
                                wrote on last edited by
                                #20

                                That reminds me of my first Oracle night school lesson. The guy next to me was doing something excessively complicated, so I said (genuinely not understanding) "Why do it that way instead of x?" He replied "Because I can!" The lecturer then made some disparaging remarks about programmers!

                                Life is like a s**t sandwich; the more bread you have, the less s**t you eat.

                                N 1 Reply Last reply
                                0
                                • P PhilLenoir

                                  That reminds me of my first Oracle night school lesson. The guy next to me was doing something excessively complicated, so I said (genuinely not understanding) "Why do it that way instead of x?" He replied "Because I can!" The lecturer then made some disparaging remarks about programmers!

                                  Life is like a s**t sandwich; the more bread you have, the less s**t you eat.

                                  N Offline
                                  N Offline
                                  newton saber
                                  wrote on last edited by
                                  #21

                                  PhilLenoir wrote:

                                  lecturer then made some disparaging remarks about programmers!

                                  Programmers cannot be trusted!!! Programmers are idiots of the second kind!!! If it were up to me, I'd ban all programming. Google Is Stupid, Of Course Also, consider the stupidity of http://google.com. Why would I want to search all of those web pages? I do not! What I want is the ONE web page that answers my EXACT question. Stupid programmers. ;P Driverless Cars? Question: What is Google working on now? Answer: driverless cars. Utterly stupid. What I really want is to get to the place I am going. So get me there already. Figure that out and we don't need no stinking programmers. In the meantime, I guess we'll have to put up with them.

                                  P 1 Reply Last reply
                                  0
                                  • N newton saber

                                    PhilLenoir wrote:

                                    lecturer then made some disparaging remarks about programmers!

                                    Programmers cannot be trusted!!! Programmers are idiots of the second kind!!! If it were up to me, I'd ban all programming. Google Is Stupid, Of Course Also, consider the stupidity of http://google.com. Why would I want to search all of those web pages? I do not! What I want is the ONE web page that answers my EXACT question. Stupid programmers. ;P Driverless Cars? Question: What is Google working on now? Answer: driverless cars. Utterly stupid. What I really want is to get to the place I am going. So get me there already. Figure that out and we don't need no stinking programmers. In the meantime, I guess we'll have to put up with them.

                                    P Offline
                                    P Offline
                                    PhilLenoir
                                    wrote on last edited by
                                    #22

                                    I retire in 8 weeks, so please wait until then! :)

                                    Life is like a s**t sandwich; the more bread you have, the less s**t you eat.

                                    1 Reply Last reply
                                    0
                                    • A Amarnath S

                                      Came across a folder having files with these names: Eighth.txt Eleventh.txt Fifth.txt First.txt Fourth.txt Ninth.txt Second.txt Seventh.txt Sixth.txt Tenth.txt Third.txt Not easy to sort :-(

                                      B Offline
                                      B Offline
                                      BillWoodruff
                                      wrote on last edited by
                                      #23

                                      Edit Feb. 13, 2015: revised linked-to file referred to here in #2. so it is internally consistent. Included sample object structure to read into by usual file-read techniques. My solution to a similar quest was: 1.Copy the ordinal table here: [^]. 2. massage it into usable form as a data file: [^]. I used the tilde (~) as the in-row item delimiter so integers could be used with commas (as in 10,000), the usual CR/LF as the row delimiter. Could probably use some more massaging. 3. parse the data file into a custom Collection after reading it, filter out what I wanted, then serialize the filtered result it for future use. The collection can be defined as simply as:

                                      // required
                                      using System.Collections.Generic;

                                      public class OrdinalData : List
                                      {
                                      // removed because the code belongs to a client
                                      }

                                      // string numberName
                                      // integer number
                                      // string roman numeral
                                      // string ordinal number
                                      // string classifier
                                      // example format: one~1~I~first~1st
                                      public class OrdinalNumberData
                                      {
                                      public string NumberName { set; get; }
                                      public int Number { set; get; }
                                      public string RomanNumeral { set; get; }
                                      public string OrdinalNumber { set; get; }
                                      public string Classifier { set; get; }
                                      }

                                      «I'm asked why doesn't C# implement feature X all the time. The answer's always the same: because no one ever designed, specified, implemented, tested, documented, shipped that feature. All six of those things are necessary to make a feature happen. They all cost huge amounts of time, effort and money.» Eric Lippert, Microsoft, 2009

                                      A realJSOPR 2 Replies Last reply
                                      0
                                      • B BillWoodruff

                                        Edit Feb. 13, 2015: revised linked-to file referred to here in #2. so it is internally consistent. Included sample object structure to read into by usual file-read techniques. My solution to a similar quest was: 1.Copy the ordinal table here: [^]. 2. massage it into usable form as a data file: [^]. I used the tilde (~) as the in-row item delimiter so integers could be used with commas (as in 10,000), the usual CR/LF as the row delimiter. Could probably use some more massaging. 3. parse the data file into a custom Collection after reading it, filter out what I wanted, then serialize the filtered result it for future use. The collection can be defined as simply as:

                                        // required
                                        using System.Collections.Generic;

                                        public class OrdinalData : List
                                        {
                                        // removed because the code belongs to a client
                                        }

                                        // string numberName
                                        // integer number
                                        // string roman numeral
                                        // string ordinal number
                                        // string classifier
                                        // example format: one~1~I~first~1st
                                        public class OrdinalNumberData
                                        {
                                        public string NumberName { set; get; }
                                        public int Number { set; get; }
                                        public string RomanNumeral { set; get; }
                                        public string OrdinalNumber { set; get; }
                                        public string Classifier { set; get; }
                                        }

                                        «I'm asked why doesn't C# implement feature X all the time. The answer's always the same: because no one ever designed, specified, implemented, tested, documented, shipped that feature. All six of those things are necessary to make a feature happen. They all cost huge amounts of time, effort and money.» Eric Lippert, Microsoft, 2009

                                        A Offline
                                        A Offline
                                        Amarnath S
                                        wrote on last edited by
                                        #24

                                        Wow. 5 from me.

                                        B 1 Reply Last reply
                                        0
                                        • realJSOPR realJSOP

                                          Solves for the known set, but what about twelfth.txt, thirteenth.txt, etc?

                                          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                          -----
                                          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                          -----
                                          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #25

                                          Start with this little beauty:

                                          string[] nos = {"", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth",
                                          "tenth", "eleventh", "twelfth", "thirteeth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth",
                                          "twenty", "twenty first", "twenty second", "twenty third", "twenty fourth", "twenty fifth", "twenty sixth", "twenty seventh", "twenty eigth", "twenty ninth",
                                          "thirty", "thirty first", "thirty second", "thirty third", "thirty fourth", "thirty fifth", "thirty sixth", "thirty seventh", "thirty eigth", "thirty ninth",
                                          "forty", "forty first", "forty second", "forty third", "forty fourth", "forty fifth", "forty sixth", "forty seventh", "forty eigth", "forty ninth",
                                          "fifty", "fifty first", "fifty second", "fifty third", "fifty fourth", "fifty fifth", "fifty sixth", "fifty seventh", "fifty eigth", "fifty ninth",
                                          "sixty", "sixty first", "sixty second", "sixty third", "sixty fourth", "sixty fifth", "sixty sixth", "sixty seventh", "sixty eigth", "sixty ninth",
                                          "seventy", "seventy first", "seventy second", "seventy third", "seventy fourth", "seventy fifth", "seventy sixth", "seventy seventh", "seventy eigth", "seventy ninth",
                                          "eighty", "eighty first", "eighty second", "eighty third", "eighty fourth", "eighty fifth", "eighty sixth", "eighty seventh", "eighty eigth", "eighty ninth",
                                          "ninety", "ninety first", "ninety second", "ninety third", "ninety fourth", "ninety fifth", "ninety sixth", "ninety seventh", "ninety eigth", "ninety ninth"
                                          };

                                          (Note that you'll have to misspell some of the file names to match... :sigh: ) http://www.codeproject.com/Feature/WeirdAndWonderful.aspx?fid=392254&select=4929745#xx4929745xx[^]

                                          K 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