Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory.GetFiles on network folder

How can I get Directory.GetFiles() to check a networked folder?

I have the following line of code in my project:

string[] array2 = Directory.GetFiles(targetFolder, "*.zip");

The variable targetFolder is grabbed from my appSettings files and resembles:\\myNetwork\\Project\\TargetFolder\\

However, when I debug my project, Directory.GetFiles() changes it to:C:\\myNetwork\\Project\\TargetFolder\\ which is incorrect and fails.

How can I fix this?

like image 251
N0xus Avatar asked May 16 '26 19:05

N0xus


1 Answers

Your network path should start with two slashes which are special characters, so you should use double on those as well:

\\\\myNetwork\\Project\\TargetFolder

Notice the four slashes in front (which actually represent two).

like image 147
JuanR Avatar answered May 18 '26 07:05

JuanR