Created
March 30, 2018 12:02
-
-
Save MuhammadFaizanKhan/d7a89596349eb69cfe34e056a6022fcf to your computer and use it in GitHub Desktop.
File Extension Converter - Convert selected extension files from a folder to desired extension.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FileExtensionConverter | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
bool quitApp = false; | |
do | |
{ | |
Console.WriteLine("\t\t\t**Files Extension Converter**"); | |
Console.WriteLine("********************************************************************************\n"); | |
Console.WriteLine("Note: Please Make backup of source path first.\n"); | |
Console.Write("Enter Source Path : "); | |
string sourceDirectory = Console.ReadLine(); | |
//string sourceDirectory = @"C:\Users\Faizan Khan\Desktop\CarStuckDummy"; | |
DirectoryInfo di = new DirectoryInfo(sourceDirectory); | |
Console.Write("Source Extension : "); | |
string sourceExtension = Console.ReadLine(); | |
if (sourceExtension.StartsWith(".")) | |
{ | |
sourceExtension = "*" + sourceExtension; | |
} | |
else | |
{ | |
sourceExtension = "*." + sourceExtension; | |
} | |
Console.Write("Convert Extension : "); | |
string convertedExtension = Console.ReadLine(); | |
if (!convertedExtension.StartsWith(".")) | |
{ | |
convertedExtension = "." + convertedExtension; | |
} | |
Console.WriteLine("\n\n Do you want converte all the files in " + convertedExtension + " extension? (y/n)"); | |
string allowConversion = Console.ReadLine().ToLower(); | |
if (allowConversion == "y" || allowConversion == "yes" || allowConversion == "yeah") | |
{ | |
FileInfo[] files = di.GetFiles(sourceExtension); | |
for (int i = 0; i < files.Length; i++) | |
{ | |
string fileNameWithPath = files[i].DirectoryName + "\\" + files[i].Name; | |
Console.WriteLine("Converting : " + fileNameWithPath); | |
File.Move(fileNameWithPath, Path.ChangeExtension(fileNameWithPath, convertedExtension)); | |
} | |
Console.WriteLine(); | |
Console.WriteLine("Total " + files.Length + " files " + sourceExtension + " has converted to " + convertedExtension + " successfully."); | |
} | |
Console.WriteLine("\n\n\nDo you want to Quit the application? (y/n)"); | |
string isQuitApplication = Console.ReadLine().ToLower(); | |
if (allowConversion == "y" || allowConversion == "yes" || allowConversion == "yeah") | |
{ | |
Environment.Exit(0); | |
quitApp = true; | |
} | |
else | |
{ | |
Console.Clear(); | |
quitApp = false; | |
} | |
} while (!quitApp); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment