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. System.IO Project for beginners

System.IO Project for beginners

Scheduled Pinned Locked Moved C#
csharplinqgraphicshelp
3 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.
  • B Offline
    B Offline
    bdeklerk
    wrote on last edited by
    #1

    Im posting this to see what people come up with in this project. I dont need help with this but am in the process of trying to figure out system.io. Ive started the project off which is a windows form with a Get Folders and Files button which then opens a FolderBrowserDialog to let you pick the directory you want to list on the listbox with its subdirectories and files. 1) How can we rename a certain directory listed in the listbox 2) How do we remove unwanted directories 3) How do we check for duplicate files or directories, and remove one) 4) How do we remove unwanted characters in directory or file names. Feel free to add other points that we could do with this project.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;

    namespace MusicProject
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

        private void btnGetFolders\_Click(object sender,                                      EventArgs e)
        {
            listBox1.Items.Clear();
            //To get the FolderBrowserDialog to choose the correct folder.
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //To get all directories in the one you selected.
                foreach (string dir in Directory.GetDirectories(fbd.SelectedPath))
                {
                    DirectoryInfo dInfo = new DirectoryInfo(dir);
                    this.listBox1.Items.Add(dInfo.Name);
                }
    
                //To get all the files in the directory you selected. 
                foreach (string file in Directory.GetFiles(fbd.SelectedPath))
                {
                    FileInfo fInfo = new FileInfo(file);
                                this.listBox1.Items.Add            (fInfo.Name);
                }
            } 
        }
    }
    

    }

    D L 2 Replies Last reply
    0
    • B bdeklerk

      Im posting this to see what people come up with in this project. I dont need help with this but am in the process of trying to figure out system.io. Ive started the project off which is a windows form with a Get Folders and Files button which then opens a FolderBrowserDialog to let you pick the directory you want to list on the listbox with its subdirectories and files. 1) How can we rename a certain directory listed in the listbox 2) How do we remove unwanted directories 3) How do we check for duplicate files or directories, and remove one) 4) How do we remove unwanted characters in directory or file names. Feel free to add other points that we could do with this project.

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.IO;

      namespace MusicProject
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }

          private void btnGetFolders\_Click(object sender,                                      EventArgs e)
          {
              listBox1.Items.Clear();
              //To get the FolderBrowserDialog to choose the correct folder.
              FolderBrowserDialog fbd = new FolderBrowserDialog();
              if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
              {
                  //To get all directories in the one you selected.
                  foreach (string dir in Directory.GetDirectories(fbd.SelectedPath))
                  {
                      DirectoryInfo dInfo = new DirectoryInfo(dir);
                      this.listBox1.Items.Add(dInfo.Name);
                  }
      
                  //To get all the files in the directory you selected. 
                  foreach (string file in Directory.GetFiles(fbd.SelectedPath))
                  {
                      FileInfo fInfo = new FileInfo(file);
                                  this.listBox1.Items.Add            (fInfo.Name);
                  }
              } 
          }
      }
      

      }

      D Offline
      D Offline
      ddecoy
      wrote on last edited by
      #2

      System.IO.Directory.Move(@"C:\olddir", @"C:\newdir");

      System.IO.Directory.Delete(@"C:\olddir",false);

      1. ?? 4)

      var cleanDir = (@"C:\olddir").Replace('unwantedChar',"");
      System.IO.Directory.Move(@"C:\olddir",cleanDir);

      1 Reply Last reply
      0
      • B bdeklerk

        Im posting this to see what people come up with in this project. I dont need help with this but am in the process of trying to figure out system.io. Ive started the project off which is a windows form with a Get Folders and Files button which then opens a FolderBrowserDialog to let you pick the directory you want to list on the listbox with its subdirectories and files. 1) How can we rename a certain directory listed in the listbox 2) How do we remove unwanted directories 3) How do we check for duplicate files or directories, and remove one) 4) How do we remove unwanted characters in directory or file names. Feel free to add other points that we could do with this project.

        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Linq;
        using System.Text;
        using System.Windows.Forms;
        using System.IO;

        namespace MusicProject
        {
        public partial class Form1 : Form
        {
        public Form1()
        {
        InitializeComponent();
        }

            private void btnGetFolders\_Click(object sender,                                      EventArgs e)
            {
                listBox1.Items.Clear();
                //To get the FolderBrowserDialog to choose the correct folder.
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //To get all directories in the one you selected.
                    foreach (string dir in Directory.GetDirectories(fbd.SelectedPath))
                    {
                        DirectoryInfo dInfo = new DirectoryInfo(dir);
                        this.listBox1.Items.Add(dInfo.Name);
                    }
        
                    //To get all the files in the directory you selected. 
                    foreach (string file in Directory.GetFiles(fbd.SelectedPath))
                    {
                        FileInfo fInfo = new FileInfo(file);
                                    this.listBox1.Items.Add            (fInfo.Name);
                    }
                } 
            }
        }
        

        }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        bdeklerk wrote:

        Feel free to add other points that we could do with this project.

        A forum-post would not be the correct place for a longer-term project. Turn it into an article, and people could collaborate. You already have answers to the other questions, which leaves #3 for me;

        bdeklerk wrote:

        1. How do we check for duplicate files or directories, and remove one)

        You can iterate over all files and folders, and for each item; calculate a hash (like md5) and put it in a dictionary, with the hash as the key and the path as the value. If you hit a double key, you'll know that the content of both files is the same - even if the filenames and/or timestamps on the files differ. Good luck :)

        Bastard Programmer from Hell :suss:

        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