Created
June 8, 2019 23:18
-
-
Save hburn7/32490b834245802d1812ff18a353d8e6 to your computer and use it in GitHub Desktop.
Stage's Complicated File Renamer :^)
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
using System; | |
using System.IO; | |
using System.Linq; | |
namespace FileChallenge | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var file = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}/text.txt"; | |
if (File.Exists(file)) | |
{ | |
Console.WriteLine("Welcome to the file renamer!"); | |
Console.WriteLine($"File to Rename: {file}"); | |
Console.WriteLine(); | |
Console.WriteLine("What would you like to rename your file to?"); | |
var newName = Console.ReadLine(); | |
Console.WriteLine("Got it."); | |
var fileName = newName.Split('.').First(); | |
var fileSuffix = newName.Split('.').Last(); | |
string newFileNameString = ""; | |
foreach (char letter in fileName) | |
{ | |
newFileNameString += letter; | |
} | |
if(!newFileNameString.Contains(".txt")) | |
newFileNameString += ".txt"; | |
var newFileLocation = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}/{newFileNameString}"; | |
File.Copy(file, newFileLocation, true); | |
File.Delete(file); | |
Console.WriteLine("Successfully renamed the file!"); | |
} | |
else | |
{ | |
File.OpenWrite($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}/text.txt"); | |
Console.WriteLine("I didn't find that file so I created it!"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment