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. help me in this program

help me in this program

Scheduled Pinned Locked Moved C#
csharphelp
5 Posts 3 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.
  • N Offline
    N Offline
    Nettai
    wrote on last edited by
    #1

    i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program

    private void button1_Click(object sender, EventArgs e)
    {

           try
            {
                
                string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles";
                string path2 = "\\\\";
                string path4 = ".txt";
                DirectoryInfo dir1 = new DirectoryInfo(path1);
                dir1.Create();
                                             
                DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles");
                FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories);
                for(int t=1;t<280;t++)
                {
                   string path3=Convert.ToString(t);
                   string path=path1+path2+path3+path4;
                   
                   FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                   StreamWriter sw = new StreamWriter(fs);
                   
    
                foreach (FileInfo FI in FileList)
                {
                    FileStream fs1 = FI.OpenRead();
                    StreamReader sr = new StreamReader(fs1);
                    int i = 1;
    
                    while (sr.ReadLine() != null)
                    {
                        string d="";                      
                       
                            if (t == i)
                            {
                                    
    
                                    d = sr.ReadLine();
                                    sw.WriteLine(d);
                                    break;
                                
                            }
                          i++;
                        
                    }
    
                  }
    
               
            }
                //fs.Close();
                //sw.Close();
        }
    
    X N D 3 Replies Last reply
    0
    • N Nettai

      i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program

      private void button1_Click(object sender, EventArgs e)
      {

             try
              {
                  
                  string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles";
                  string path2 = "\\\\";
                  string path4 = ".txt";
                  DirectoryInfo dir1 = new DirectoryInfo(path1);
                  dir1.Create();
                                               
                  DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles");
                  FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories);
                  for(int t=1;t<280;t++)
                  {
                     string path3=Convert.ToString(t);
                     string path=path1+path2+path3+path4;
                     
                     FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                     StreamWriter sw = new StreamWriter(fs);
                     
      
                  foreach (FileInfo FI in FileList)
                  {
                      FileStream fs1 = FI.OpenRead();
                      StreamReader sr = new StreamReader(fs1);
                      int i = 1;
      
                      while (sr.ReadLine() != null)
                      {
                          string d="";                      
                         
                              if (t == i)
                              {
                                      
      
                                      d = sr.ReadLine();
                                      sw.WriteLine(d);
                                      break;
                                  
                              }
                            i++;
                          
                      }
      
                    }
      
                 
              }
                  //fs.Close();
                  //sw.Close();
          }
      
      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      you're writing 279 same files...plus

      if (t == i)
      {

                                      d = sr.ReadLine();
                                      sw.WriteLine(d);
                                      break;
                                  
                              }
      

      this will break in every first while loop File.Copy() can do what you need

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

      ----------------------------------------------- 128 bit encrypted signature, crack if you can

      1 Reply Last reply
      0
      • N Nettai

        i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program

        private void button1_Click(object sender, EventArgs e)
        {

               try
                {
                    
                    string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles";
                    string path2 = "\\\\";
                    string path4 = ".txt";
                    DirectoryInfo dir1 = new DirectoryInfo(path1);
                    dir1.Create();
                                                 
                    DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles");
                    FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories);
                    for(int t=1;t<280;t++)
                    {
                       string path3=Convert.ToString(t);
                       string path=path1+path2+path3+path4;
                       
                       FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                       StreamWriter sw = new StreamWriter(fs);
                       
        
                    foreach (FileInfo FI in FileList)
                    {
                        FileStream fs1 = FI.OpenRead();
                        StreamReader sr = new StreamReader(fs1);
                        int i = 1;
        
                        while (sr.ReadLine() != null)
                        {
                            string d="";                      
                           
                                if (t == i)
                                {
                                        
        
                                        d = sr.ReadLine();
                                        sw.WriteLine(d);
                                        break;
                                    
                                }
                              i++;
                            
                        }
        
                      }
        
                   
                }
                    //fs.Close();
                    //sw.Close();
            }
        
        N Offline
        N Offline
        Nettai
        wrote on last edited by
        #3

        thanks for ur reply....i don't know how file.copy() method is going to help in this program.here i am not copying the file to another path...i am just reading the the same row of every text file and copy it into new file..and u told me that this program will write 279 same files...but i am getting 279 different text files with different memory sizes....

        X 1 Reply Last reply
        0
        • N Nettai

          i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program

          private void button1_Click(object sender, EventArgs e)
          {

                 try
                  {
                      
                      string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles";
                      string path2 = "\\\\";
                      string path4 = ".txt";
                      DirectoryInfo dir1 = new DirectoryInfo(path1);
                      dir1.Create();
                                                   
                      DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles");
                      FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories);
                      for(int t=1;t<280;t++)
                      {
                         string path3=Convert.ToString(t);
                         string path=path1+path2+path3+path4;
                         
                         FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                         StreamWriter sw = new StreamWriter(fs);
                         
          
                      foreach (FileInfo FI in FileList)
                      {
                          FileStream fs1 = FI.OpenRead();
                          StreamReader sr = new StreamReader(fs1);
                          int i = 1;
          
                          while (sr.ReadLine() != null)
                          {
                              string d="";                      
                             
                                  if (t == i)
                                  {
                                          
          
                                          d = sr.ReadLine();
                                          sw.WriteLine(d);
                                          break;
                                      
                                  }
                                i++;
                              
                          }
          
                        }
          
                     
                  }
                      //fs.Close();
                      //sw.Close();
              }
          
          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Take a look at File.ReadAllLines method. Now since you know the line number to read, just get that from the array returned. Then once you have read all the files, then write everything to the file in one go. This can be done using in built methods in File class. Also, when you reply to anyone, use reply link in that very post and not your own.

          जय हिंद

          1 Reply Last reply
          0
          • N Nettai

            thanks for ur reply....i don't know how file.copy() method is going to help in this program.here i am not copying the file to another path...i am just reading the the same row of every text file and copy it into new file..and u told me that this program will write 279 same files...but i am getting 279 different text files with different memory sizes....

            X Offline
            X Offline
            Xmen Real
            wrote on last edited by
            #5

            nettai wrote:

            ..but i am getting 279 different text files with different memory sizes....

            yes, if you dont mind then your code is very tacky. All you need to do is that read all lines from each text file using File.ReadAllLines() as Danish said. That will return string[] and you can rip the line by index then add to the generic string list List. When you done, write entire list using File.WriteAllLines()(you will need to use ToArray() to get the array from list).

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

            ----------------------------------------------- 128 bit encrypted signature, crack if you can

            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