How to check if a file exists when it was no file extension? C# -


this question has answer here:

the file test has no extension , need either move or rename file extension

if(file.exists(@"c:\\users" + environment.username + "\\desktop\\test")) {                                                                 /\                                                file has no file extension } 

i created file named test no extension in folder m:\incoming.

running following code works in both cases:

if (file.exists(@"m:\incoming\test"))     console.writeline("exists");  if (file.exists(@"m:\\incoming\\test"))     console.writeline("exists"); 

when using @ not need specify 2 slashes, although makes no difference anyway in example.

output:

exists

exists

your problem in way in concatenating strings.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -