I want to clear some space from my hard drive. I have a few mp4s I downloaded from youtube and I just don't have time to watch them all. I want to delete them to make space on my hard drive but I don't want to lose them as I might not remember the title of a video of I want to go find it again. So I made this program to find all the files with .mp4 in a directory and write the file names to file so I can delete the .mp4s, thus freeing space in my computer. Problem is....the application crashes with this error:
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace FileData
{
class Program
{
static void Main(string[] args)
{
string fileName = "video_filenames.txt";
DirectoryInfo di = new DirectoryInfo("C:\\Users\\admin\\Documents");
if (di != null)
{
Console.Write("Directory exists");
FileInfo[] fi = di.GetFiles("*.mp4");
string str = "";
if (fi != null)
{
File.Create(fileName);
if (File.Exists(fileName))
{
foreach (FileInfo file in fi)
{
str += file.FullName;
}
}
File.WriteAllText(fileName, str + "\n");
}
}
}
}
}