+ 2
How to catch exception if file doesn't exist?
I wrote this small script below to enter a filename, along with it's full path(ie: C:\Program Files (x86)\Audacity\audacity.exe) and it spits out the filesize in bytes. The script works, as long as you don't typo the path/filename. How can I do a an if statement to check that the file actually exists first? Code below: Console.WriteLine("Enter a filename with full path: "); var input = @Console.ReadLine(); FileInfo fileSize = new FileInfo(input); long fullSize = fileSize.Length; Console.WriteLine("The filesize of {0} is {1} bytes.", input, fullSize);
1 Answer