Daniel Lip

Daniel Lip

  • NA
  • 64
  • 22.1k

How can i merge the files and directories ?

Feb 5 2013 1:52 PM
I will try to describe it again here shorter or more clear then before since I don't need to touch the new class code only the code in Form1 :


This is the code:
  for (int i = 0; i < LR.Count; i++) { if (LR[i].end }
For example LR[I].start is 88 and LR[I].end  is now 96 and then in the next itertion LR[I].start is 97 and LR[I].end is 100.
In this case I want to build a new LR List wich will contain LR[I].start is 88 and LR[I].end is 100
But in case that the next LR[I].end was 100 and the next LR[I].start is 120 then do not merge the end and the start keep the List as it is. Then if the next end was 127 and the next start is 128 then merge it again to the next end and create again a new List. And so on.
This is how I build the LR List and the end and start Lists:
 
lightningsRegions = new List<string>(); LR = new List<Lightnings_Extractor.Lightnings_Region>(); int fp = 0; List<int> rise, fall; rise = new List<int>(); fall = new List<int>(); for (int i = 35; i < averagesOriginal.Count - 35; i++) { if (averagesOriginal[i] <= resultings[i - 35]) { if (averagesOriginal[i + 1] > resultings[i - 35 + 1]) { if (fp == 0) { fp = i; } rise.Add(i-padBeforeAndAfter); } } } for (int i = fp + 1; i < averagesOriginal.Count - 35; i++) { if ((i - 35) < 0) { } else { if (averagesOriginal[i] > resultings[i - 35]) { if (averagesOriginal[i + 1] <= resultings[i - 35 + 1]) { fall.Add(i+padBeforeAndAfter); } } } } if ((rise.Count - fall.Count) == 1) { rise.RemoveAt(rise.Count - 1); } if (fall.Count != rise.Count) { throw new Exception("uneven falls and rise....we should deal with it..but not for now"); } for (int i = 0; i < fall.Count; i++) { Lightnings_Extractor.Lightnings_Region LReg = new Lightnings_Extractor.Lightnings_Region(); LReg.start = rise[i]; LReg.end = fall[i]; LR.Add(LReg); } for (int i = 0; i < LR.Count; i++) { if (LR[i].end int len = LR[i].end - LR[i].start; lightningsRegions.Add("Lightning " + i.ToString() + " Length " + len.ToString() + " [" + LR[i].start.ToString() + " - " + LR[i].end.ToString() + "]"); }
The idea should be to merge end and start that are the same or close like end was 100 and the next start is 100 or 101 then merge it until the next end. Then check the next start to see if it's the same or the continue of the last end if so merge if not keep building the list as it is.
If it is for example end 100 and start 100 or 101 then build a new List of LR with the fixed places merged places.
The List LR is a List of a class Lightnings_Region in this class I have:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lightnings_Extractor { class Lightnings_Region { public int start = 0; public int end = 0; public Lightnings_Region() { } } }So the List LR is type of class and contain all the start and end couples from the rise and fall Lists.


This is what I did so far and im stuck not sure how to do it:


this is what I did now:

Im looping through the List LR wich contain the start and end variables.
for (int i = 0; i < LR.Count; i++) { if (i < LR.Count - 1) { if (LR[i].end + 1 == LR[i + 1].start) { Lightnings_Extractor.Lightnings_Region LReg = new Lightnings_Extractor.Lightnings_Region(); LReg.start = rise[i]; LReg.end = fall[i]; LR.Add(LReg); } else { Lightnings_Extractor.Lightnings_Region LReg = new Lightnings_Extractor.Lightnings_Region(); LReg.start = rise[i]; LReg.end = fall[i]; LR.Add(LReg); } } int len = LR[i].end - LR[i].start; lightningsRegions.Add("Lightning " + i.ToString() + " Length " + len.ToString() + " [" + LR[i].start.ToString() + " - " + LR[i].end.ToString() + "]"); }Now if im not wrong what i want to do is that if they are == like this: LR[i].end + 1 == LR[i + 1].start then i want to build again the new List LR of start's and end's and if it's not == then just to add to existted LR List the next end and start. I'm not if it's any good what i did so far and im not sure how do i make a new LR List if they are == but also to keep the other start and end that wasn't ==
If I will make LR = new....it will delete the old ends and starts that are not == that was already in the List.


So im stuck here.


I just uploaded a zip file with a text file inside.