Using Path Of Created Sub Directory In C# with Example



You can programmatically create a folder on your computer, create a subfolder, create a file in the subfolder, and write data to the file.

using System.IO;
using System;

namespace CSharpFilesAndStreams
{
    class Program
    {
        static void Main(string[] args)
        {
            FunWithDirectoryType();
        }

		static void FunWithDirectoryType()
		{
			// List all drives on current computer.
			string[] drives = Directory.GetLogicalDrives();
			Console.WriteLine("Here are your drives:");

			foreach (string s in drives)
				Console.WriteLine("--> {0} ", s);
			
			// Delete what was created.
			Console.WriteLine("Press Enter to delete directories");
			Console.ReadLine();
			try
			{
				Directory.Delete(@"C:\MyFolder");
				// The second parameter specifies whether you wish to destroy any subdirectories.
				Directory.Delete(@"C:\MyFolder2", true);
			}
			catch (IOException e)
			{
			Console.WriteLine(e.Message);
			}
		}
	}
}	

0 Comment's

Comment Form

Submit Comment