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 index in C#

List index in C#

Scheduled Pinned Locked Moved C#
csharpdatabasexml
4 Posts 2 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.
  • M Offline
    M Offline
    mrithula8
    wrote on last edited by
    #1

    Hi I want to list folders,subfolders and files from all drives in a system.I tried a code which works well for C:\.I want the same for the other drives.I have listed the drives in listbox.Please give your suggestions.

    private void PaintList(String sss)
    {

            try
                {
                    reader = new XmlTextReader("path.xml");
    
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Text: //Display the text in each element.
                                //   Console.WriteLine(reader.Value);
                                String s1;
                                s1 = reader.Value;
                                String ss;
                                ss = listBox1.SelectedItem.ToString();
                                sss = ss + s1;
                                object o3 = (object)sss;
    
                                DirectoryInfo dire = new DirectoryInfo(sss);
    
                                //DirectoryInfo\[\] dirs = dire.GetDirectories();
    
                                if (dire.Exists)
                                {
                                    String\[\] folder;
                                    folder = Directory.GetDirectories(sss);
                                    foreach (string foldername in folder)
                                    {
                                        DirectoryInfo di = new DirectoryInfo(foldername);
                                        if (di.Exists)
                                        {
                                            String\[\] files;
                                            files = Directory.GetFiles(foldername, "\*.exe\*");
    
                                            //FileInfo\[\] fi = dire.GetFiles();
    
                                            foreach (String filename in files)
                                            {
                                                lvi = new ListViewItem();
                                                lvi.Text = filename;
                                                listView1.Items.Add(lvi);
    
                                                lvsi = new ListViewItem.ListViewSubItem();
                                                lvsi.Text = filename.Length.ToString();
                                                lvi.SubItems.Add(lvsi);
    
    X 1 Reply Last reply
    0
    • M mrithula8

      Hi I want to list folders,subfolders and files from all drives in a system.I tried a code which works well for C:\.I want the same for the other drives.I have listed the drives in listbox.Please give your suggestions.

      private void PaintList(String sss)
      {

              try
                  {
                      reader = new XmlTextReader("path.xml");
      
                      while (reader.Read())
                      {
                          switch (reader.NodeType)
                          {
                              case XmlNodeType.Text: //Display the text in each element.
                                  //   Console.WriteLine(reader.Value);
                                  String s1;
                                  s1 = reader.Value;
                                  String ss;
                                  ss = listBox1.SelectedItem.ToString();
                                  sss = ss + s1;
                                  object o3 = (object)sss;
      
                                  DirectoryInfo dire = new DirectoryInfo(sss);
      
                                  //DirectoryInfo\[\] dirs = dire.GetDirectories();
      
                                  if (dire.Exists)
                                  {
                                      String\[\] folder;
                                      folder = Directory.GetDirectories(sss);
                                      foreach (string foldername in folder)
                                      {
                                          DirectoryInfo di = new DirectoryInfo(foldername);
                                          if (di.Exists)
                                          {
                                              String\[\] files;
                                              files = Directory.GetFiles(foldername, "\*.exe\*");
      
                                              //FileInfo\[\] fi = dire.GetFiles();
      
                                              foreach (String filename in files)
                                              {
                                                  lvi = new ListViewItem();
                                                  lvi.Text = filename;
                                                  listView1.Items.Add(lvi);
      
                                                  lvsi = new ListViewItem.ListViewSubItem();
                                                  lvsi.Text = filename.Length.ToString();
                                                  lvi.SubItems.Add(lvsi);
      
      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      use Directory.GetLogicalDrives()

      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

      M 1 Reply Last reply
      0
      • X Xmen Real

        use Directory.GetLogicalDrives()

        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

        M Offline
        M Offline
        mrithula8
        wrote on last edited by
        #3

        Hi I am getting the list of all the drives.I am able to list the files for C:\.I want to do the same for the other drives.The index of the list should change.If i use the following i have to do the same coding inside each if statement.Can you give some alternative

        int r=listBox1.SelectedIndex;
        if(r==0)
        {
        }
        if(r==1)
        {
        }

        X 1 Reply Last reply
        0
        • M mrithula8

          Hi I am getting the list of all the drives.I am able to list the files for C:\.I want to do the same for the other drives.The index of the list should change.If i use the following i have to do the same coding inside each if statement.Can you give some alternative

          int r=listBox1.SelectedIndex;
          if(r==0)
          {
          }
          if(r==1)
          {
          }

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

          string[] drives = Directory.GetLogicalDrives();
          for(int a=0;a<drive.length;a++)>
          {
          //here your code
          }

          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