mrminer mrminer - 1 year ago 114
ASP.NET (C#) Question

ASP.NET Windows Console check file

I need to make something that checks if there is only 1 .DBS file and if so put the filename of the .DBS into a variable.

So my problem is that I need to check in the folder C:\RMExport if there is a .DBS file. If there is a .DBS file I need to read that file name and put the filename into a variable.


namespace Ramasoftzipper
class Program
static void Main(string[] args)
string startPath = @"C:\RMExport";

if (System.IO.Directory.Exists("*.DBS")) ;
string[] files = System.IO.Directory.GetFiles(startPath, "*.DBS");


Answer Source

This line alone is enough to do that:

string[] files = System.IO.Directory.GetFiles(startPath,"*.DBS",System.IO.SearchOption .AllDirectories);

OR if you do not want to search inside sub folders

string[] files = System.IO.Directory.GetFiles(startPath,"*.DBS");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download