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. List problem !

List problem !

Scheduled Pinned Locked Moved C#
helpdatabasequestion
7 Posts 6 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.
  • _ Offline
    _ Offline
    _Q12_
    wrote on last edited by
    #1

    /*I work at this code from a month now, and still is full of bugs...
    I decided to get help, because i can not think clear (i slept a lot, but did not helped)
    When i change something in the UPcode, something in the DOWNcode is mess up. If i change something, a fucking chain of events crack in my face (and they are not compiler errors) - just the functionality of the software.
    What i want to do here is like this:
    Look into a saved pls list of movies, and copy all the lines inside it( ---unordered---, like they were saved last time)
    -compare what is in director with what is saved in list
    if same data, skip all / load default
    if new files(movies) in dir, bring new lines in front of list (or behind)
    if missing files in list, clear list, but mentain the last (unordered) lines in file
    -if file does not exist, make one new (default - in alphabetical order)*/

        private void Form1\_Load(object sender, EventArgs e)
        {
            //Add movies from Directory
            DirectoryInfo di = new DirectoryInfo(path);
            foreach (var movie in di.GetFiles())
            {
                foreach (var extension in extensionsForMovies)
                {
                    if (movie.Extension.ToUpper() == extension)
                    {
                        List1.Add(movie.Name);
                    }
                }
            }
          
            DateTime dt = DateTime.UtcNow;
            string day = dt.Day.ToString(); if (dt.Day < 10) day = 0 + dt.Day.ToString();//if Day<10 put 0 in front (01,02,03...)
            string month = dt.Month.ToString(); if (dt.Month < 10) month = 0 + dt.Month.ToString();
            string date = dt.Year.ToString() + month + day;
    
    
            index = new FileInfo("   index" + List1.Count + "  \[" + date + "\].pls");
            label1.Text = List1.Count + " files/" + nrMovies() + " saved";
        }
    
    
    
        List List1 = new List(); //movie\_List   list of movies
        List List2 = new List(); //file\_List    list of saves
        List List3 = new List(); //temp\_List
    

    private void button1Create_Click(object sender, EventArgs e)
    {
    // if a *.PLS file exist read all data
    bool isPLSfile = false;
    DirectoryInfo di = new DirectoryInfo(path);
    foreach (var movie in di.GetFiles())
    {
    if (movie.Extension.ToUpper() == ".PLS")
    {

    A OriginalGriffO L P P 5 Replies Last reply
    0
    • _ _Q12_

      /*I work at this code from a month now, and still is full of bugs...
      I decided to get help, because i can not think clear (i slept a lot, but did not helped)
      When i change something in the UPcode, something in the DOWNcode is mess up. If i change something, a fucking chain of events crack in my face (and they are not compiler errors) - just the functionality of the software.
      What i want to do here is like this:
      Look into a saved pls list of movies, and copy all the lines inside it( ---unordered---, like they were saved last time)
      -compare what is in director with what is saved in list
      if same data, skip all / load default
      if new files(movies) in dir, bring new lines in front of list (or behind)
      if missing files in list, clear list, but mentain the last (unordered) lines in file
      -if file does not exist, make one new (default - in alphabetical order)*/

          private void Form1\_Load(object sender, EventArgs e)
          {
              //Add movies from Directory
              DirectoryInfo di = new DirectoryInfo(path);
              foreach (var movie in di.GetFiles())
              {
                  foreach (var extension in extensionsForMovies)
                  {
                      if (movie.Extension.ToUpper() == extension)
                      {
                          List1.Add(movie.Name);
                      }
                  }
              }
            
              DateTime dt = DateTime.UtcNow;
              string day = dt.Day.ToString(); if (dt.Day < 10) day = 0 + dt.Day.ToString();//if Day<10 put 0 in front (01,02,03...)
              string month = dt.Month.ToString(); if (dt.Month < 10) month = 0 + dt.Month.ToString();
              string date = dt.Year.ToString() + month + day;
      
      
              index = new FileInfo("   index" + List1.Count + "  \[" + date + "\].pls");
              label1.Text = List1.Count + " files/" + nrMovies() + " saved";
          }
      
      
      
          List List1 = new List(); //movie\_List   list of movies
          List List2 = new List(); //file\_List    list of saves
          List List3 = new List(); //temp\_List
      

      private void button1Create_Click(object sender, EventArgs e)
      {
      // if a *.PLS file exist read all data
      bool isPLSfile = false;
      DirectoryInfo di = new DirectoryInfo(path);
      foreach (var movie in di.GetFiles())
      {
      if (movie.Extension.ToUpper() == ".PLS")
      {

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      So where are you facing the problem?

      Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

      _ 1 Reply Last reply
      0
      • A Abhinav S

        So where are you facing the problem?

        Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

        _ Offline
        _ Offline
        _Q12_
        wrote on last edited by
        #3

        I am thinking on my code as a structure - i want my code to make it more practical, usable, coder friendly, with good structure and architecture. Maybe this is the problem. The actual code is working fine- but when i have to change something, i must spend days to debug the shit out. Thanks Abhinav.

        1 Reply Last reply
        0
        • _ _Q12_

          /*I work at this code from a month now, and still is full of bugs...
          I decided to get help, because i can not think clear (i slept a lot, but did not helped)
          When i change something in the UPcode, something in the DOWNcode is mess up. If i change something, a fucking chain of events crack in my face (and they are not compiler errors) - just the functionality of the software.
          What i want to do here is like this:
          Look into a saved pls list of movies, and copy all the lines inside it( ---unordered---, like they were saved last time)
          -compare what is in director with what is saved in list
          if same data, skip all / load default
          if new files(movies) in dir, bring new lines in front of list (or behind)
          if missing files in list, clear list, but mentain the last (unordered) lines in file
          -if file does not exist, make one new (default - in alphabetical order)*/

              private void Form1\_Load(object sender, EventArgs e)
              {
                  //Add movies from Directory
                  DirectoryInfo di = new DirectoryInfo(path);
                  foreach (var movie in di.GetFiles())
                  {
                      foreach (var extension in extensionsForMovies)
                      {
                          if (movie.Extension.ToUpper() == extension)
                          {
                              List1.Add(movie.Name);
                          }
                      }
                  }
                
                  DateTime dt = DateTime.UtcNow;
                  string day = dt.Day.ToString(); if (dt.Day < 10) day = 0 + dt.Day.ToString();//if Day<10 put 0 in front (01,02,03...)
                  string month = dt.Month.ToString(); if (dt.Month < 10) month = 0 + dt.Month.ToString();
                  string date = dt.Year.ToString() + month + day;
          
          
                  index = new FileInfo("   index" + List1.Count + "  \[" + date + "\].pls");
                  label1.Text = List1.Count + " files/" + nrMovies() + " saved";
              }
          
          
          
              List List1 = new List(); //movie\_List   list of movies
              List List2 = new List(); //file\_List    list of saves
              List List3 = new List(); //temp\_List
          

          private void button1Create_Click(object sender, EventArgs e)
          {
          // if a *.PLS file exist read all data
          bool isPLSfile = false;
          DirectoryInfo di = new DirectoryInfo(path);
          foreach (var movie in di.GetFiles())
          {
          if (movie.Extension.ToUpper() == ".PLS")
          {

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

          Being frank here: that code is rather poor. I'm not too surprised that if you change something, the rest of it starts to fall over - you don't seem to have any consistent structure or to use any good practices. Don't call things "list1" and "list2" - name them after what they do, just as you do in the comments. If you only want files which match an extension, then only retrieve file which match the extension:

                  string\[\] files = Directory.GetFiles(path, "\*.PLS");
          

          If you want all lines from a file, then just read them:

                  string\[\] lines = File.ReadAllLines(path);
          

          You can then convert this to a list with the ToList method if you need a list. And so on - try modularising this code so that you have a method doing one task, then call it from your click handler - that way, you can test the method in isolation and be sure it works. I'm not at all sure what your code is doing at the moment, so I'm not that surprised that you have problems maintaining it - it looks like you have hacked and slashed it a bit to get it working, then hacked it again to fix that bug, then...all without sitting down and working out what you are trying to achieve and doing a design of some form which meets that aim first.

          The only instant messaging I do involves my middle finger. English doesn't borrow from other languages. English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.

          "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

          1 Reply Last reply
          0
          • _ _Q12_

            /*I work at this code from a month now, and still is full of bugs...
            I decided to get help, because i can not think clear (i slept a lot, but did not helped)
            When i change something in the UPcode, something in the DOWNcode is mess up. If i change something, a fucking chain of events crack in my face (and they are not compiler errors) - just the functionality of the software.
            What i want to do here is like this:
            Look into a saved pls list of movies, and copy all the lines inside it( ---unordered---, like they were saved last time)
            -compare what is in director with what is saved in list
            if same data, skip all / load default
            if new files(movies) in dir, bring new lines in front of list (or behind)
            if missing files in list, clear list, but mentain the last (unordered) lines in file
            -if file does not exist, make one new (default - in alphabetical order)*/

                private void Form1\_Load(object sender, EventArgs e)
                {
                    //Add movies from Directory
                    DirectoryInfo di = new DirectoryInfo(path);
                    foreach (var movie in di.GetFiles())
                    {
                        foreach (var extension in extensionsForMovies)
                        {
                            if (movie.Extension.ToUpper() == extension)
                            {
                                List1.Add(movie.Name);
                            }
                        }
                    }
                  
                    DateTime dt = DateTime.UtcNow;
                    string day = dt.Day.ToString(); if (dt.Day < 10) day = 0 + dt.Day.ToString();//if Day<10 put 0 in front (01,02,03...)
                    string month = dt.Month.ToString(); if (dt.Month < 10) month = 0 + dt.Month.ToString();
                    string date = dt.Year.ToString() + month + day;
            
            
                    index = new FileInfo("   index" + List1.Count + "  \[" + date + "\].pls");
                    label1.Text = List1.Count + " files/" + nrMovies() + " saved";
                }
            
            
            
                List List1 = new List(); //movie\_List   list of movies
                List List2 = new List(); //file\_List    list of saves
                List List3 = new List(); //temp\_List
            

            private void button1Create_Click(object sender, EventArgs e)
            {
            // if a *.PLS file exist read all data
            bool isPLSfile = false;
            DirectoryInfo di = new DirectoryInfo(path);
            foreach (var movie in di.GetFiles())
            {
            if (movie.Extension.ToUpper() == ".PLS")
            {

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

            _Q12_ wrote:

            I work at this code from a month now, and still is full of bugs.

            Where? Your description in the comments section states what you want your application to do but gives no useful details of what the problems are.

            Veni, vidi, abiit domum

            1 Reply Last reply
            0
            • _ _Q12_

              /*I work at this code from a month now, and still is full of bugs...
              I decided to get help, because i can not think clear (i slept a lot, but did not helped)
              When i change something in the UPcode, something in the DOWNcode is mess up. If i change something, a fucking chain of events crack in my face (and they are not compiler errors) - just the functionality of the software.
              What i want to do here is like this:
              Look into a saved pls list of movies, and copy all the lines inside it( ---unordered---, like they were saved last time)
              -compare what is in director with what is saved in list
              if same data, skip all / load default
              if new files(movies) in dir, bring new lines in front of list (or behind)
              if missing files in list, clear list, but mentain the last (unordered) lines in file
              -if file does not exist, make one new (default - in alphabetical order)*/

                  private void Form1\_Load(object sender, EventArgs e)
                  {
                      //Add movies from Directory
                      DirectoryInfo di = new DirectoryInfo(path);
                      foreach (var movie in di.GetFiles())
                      {
                          foreach (var extension in extensionsForMovies)
                          {
                              if (movie.Extension.ToUpper() == extension)
                              {
                                  List1.Add(movie.Name);
                              }
                          }
                      }
                    
                      DateTime dt = DateTime.UtcNow;
                      string day = dt.Day.ToString(); if (dt.Day < 10) day = 0 + dt.Day.ToString();//if Day<10 put 0 in front (01,02,03...)
                      string month = dt.Month.ToString(); if (dt.Month < 10) month = 0 + dt.Month.ToString();
                      string date = dt.Year.ToString() + month + day;
              
              
                      index = new FileInfo("   index" + List1.Count + "  \[" + date + "\].pls");
                      label1.Text = List1.Count + " files/" + nrMovies() + " saved";
                  }
              
              
              
                  List List1 = new List(); //movie\_List   list of movies
                  List List2 = new List(); //file\_List    list of saves
                  List List3 = new List(); //temp\_List
              

              private void button1Create_Click(object sender, EventArgs e)
              {
              // if a *.PLS file exist read all data
              bool isPLSfile = false;
              DirectoryInfo di = new DirectoryInfo(path);
              foreach (var movie in di.GetFiles())
              {
              if (movie.Extension.ToUpper() == ".PLS")
              {

              P Offline
              P Offline
              Paulo Augusto Kunzel
              wrote on last edited by
              #6

              First, improve your readability of variables:

               //instead of:
               List List1 = new List(); //movie\_List   list of movies
               List List2 = new List(); //file\_List    list of saves
               List List3 = new List(); //temp\_List
              
               //try something like:
               List moviesList = new List(); //movie\_List   list of movies
               List savesList = new List(); //file\_List    list of saves
               List tempList = new List(); //temp\_List
              

              Also, there are FORs that you could change to foreach. Please, drop the GOTO. Although it has its uses, the same can be achieved with loop controls and it can avoid confusion.

              There are no secrets to success. It is the result of preparation, hard work, and learning from failure. Colin Powell

              1 Reply Last reply
              0
              • _ _Q12_

                /*I work at this code from a month now, and still is full of bugs...
                I decided to get help, because i can not think clear (i slept a lot, but did not helped)
                When i change something in the UPcode, something in the DOWNcode is mess up. If i change something, a fucking chain of events crack in my face (and they are not compiler errors) - just the functionality of the software.
                What i want to do here is like this:
                Look into a saved pls list of movies, and copy all the lines inside it( ---unordered---, like they were saved last time)
                -compare what is in director with what is saved in list
                if same data, skip all / load default
                if new files(movies) in dir, bring new lines in front of list (or behind)
                if missing files in list, clear list, but mentain the last (unordered) lines in file
                -if file does not exist, make one new (default - in alphabetical order)*/

                    private void Form1\_Load(object sender, EventArgs e)
                    {
                        //Add movies from Directory
                        DirectoryInfo di = new DirectoryInfo(path);
                        foreach (var movie in di.GetFiles())
                        {
                            foreach (var extension in extensionsForMovies)
                            {
                                if (movie.Extension.ToUpper() == extension)
                                {
                                    List1.Add(movie.Name);
                                }
                            }
                        }
                      
                        DateTime dt = DateTime.UtcNow;
                        string day = dt.Day.ToString(); if (dt.Day < 10) day = 0 + dt.Day.ToString();//if Day<10 put 0 in front (01,02,03...)
                        string month = dt.Month.ToString(); if (dt.Month < 10) month = 0 + dt.Month.ToString();
                        string date = dt.Year.ToString() + month + day;
                
                
                        index = new FileInfo("   index" + List1.Count + "  \[" + date + "\].pls");
                        label1.Text = List1.Count + " files/" + nrMovies() + " saved";
                    }
                
                
                
                    List List1 = new List(); //movie\_List   list of movies
                    List List2 = new List(); //file\_List    list of saves
                    List List3 = new List(); //temp\_List
                

                private void button1Create_Click(object sender, EventArgs e)
                {
                // if a *.PLS file exist read all data
                bool isPLSfile = false;
                DirectoryInfo di = new DirectoryInfo(path);
                foreach (var movie in di.GetFiles())
                {
                if (movie.Extension.ToUpper() == ".PLS")
                {

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Okay, I see many areas that can be improved. Here are a few enhancements that you might want to consider as they should make your life easier (and I'm not talking just about renaming your lists). First of all, you are mixing a lot of concerns in your code. That's a fancy way of saying that your class is trying to do too much. You should simplify and specialise so that you create classes that are responsible only for their own functionality. That makes testing and fixing a lot easier. You are relying on goto statements - I'm not going to go into a religious gotos are evil argument here as they sometimes do have their place, but in your case they are obscuring the logic. You can simplify your GetFiles when you are retrieving multiple extensions using a simple LINQ trick:

                IEnumerable<string> files = extensionsForMovies.SelectMany(filter =>
                Directory.GetFiles(currentFolder, filter, SearchOption.TopDirectoryOnly));

                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