예제 #1
0
파일: Sorter.cs 프로젝트: srenshaw/FileSort
        public List<Sorter> ReadFile(string fileName)
        {
            List<Sorter> sortList = new List<Sorter>();
            StreamReader stream = null;
            try {
                using (stream = new StreamReader(fileName)) {
                    string line;
                    while ((line = stream.ReadLine()) != null) {
                        string[] splitLine = line.Split(',');
                        Sorter sortLine = new Sorter();
                        sortLine.toFolder = splitLine[0];
                        sortLine.nameRef = splitLine[1];
                        sortList.Add(sortLine);
                    }
                }
                return sortList;

            } catch (FileNotFoundException) {
                throw new Exception("The Reference file could not be found");
            } catch (Exception) {
                throw new Exception("An error has occured please check the Reference file and try again");
            } finally {
                stream.Close();
                stream.Dispose();
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: srenshaw/FileSort
 private void btnRun_Click(object sender, EventArgs e)
 {
     picLoader.Visible = true;
     picLoader.Refresh();
     string file = lblFile.Text;
     string folder = lblFolder.Text;
     string destination = lblDestination.Text;
     Sorter sortClass = new Sorter();
     try {
         sortClass.SortFiles(sortClass.ReadFile(file), folder, destination);
     } catch (Exception ex) {
         MessageBox.Show("Something went Wrong " + ex.Message);
     } finally { picLoader.Visible = false; picLoader.Refresh(); }
 }