Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get specific file names using c#

I have 10 zip files in a folder having path like this

TargetDirectory = "C:\docs\folder\"

some of the zip files names are like this

abc-19870908.Zip 
abc-19870908.zip
abc-12345678.zip

and some are like this...

doc.zip
doc123.zip  
..

I am getting all file names by using following code...

string [] fileEntries = Directory.GetFiles(targetDirectory); 
foreach(string fileName in fileEntries)
{
  // here I need to compare , 
  // I mean I want to get only these files which are having 
  // these type of  filenames `abc-19870908.Zip`

  if (filename == "")
  {

       // I want to do something
   }
}

What i have to put in the double quotes in this line if(filename == "") to get like abc-19870908.Zip these filenames.

Would any one please suggest any idea about this?

Many thanks...

like image 656
Glory Raj Avatar asked Dec 03 '22 01:12

Glory Raj


1 Answers

If you're only interested in zip files containing a dash, you can provide a search pattern to Directory.GetFiles.

string [] fileEntries = Directory.GetFiles(targetDirectory, "*-*.zip"); 

Check out this link for more information on those search patterns: http://msdn.microsoft.com/en-us/library/wz42302f.aspx

like image 82
Brosto Avatar answered Dec 20 '22 12:12

Brosto