List problem !
-
/*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")
{ -
/*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")
{So where are you facing the problem?
Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial
-
So where are you facing the problem?
Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial
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.
-
/*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")
{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 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")
{ -
/*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")
{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
-
/*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")
{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));