DirectoryInfo.getFiles beginning with

JL. picture JL. · Jul 29, 2009 · Viewed 31.4k times · Source

I've come across some strange behavior trying to get files that start with a certain string.

Please would someone give a working example on this:

I want to get all files in a directory that begin with a certain string, but also contain the xml extension.

for example:

 apples_01.xml
 apples_02.xml
 pears_03.xml

I want to be able to get the files that begin with apples.

So far I have this code

 DirectoryInfo taskDirectory = new DirectoryInfo(this.taskDirectoryPath);
 FileInfo[] taskFiles = taskDirectory.GetFiles("*.xml");

Answer

Cerebrus picture Cerebrus · Jul 29, 2009
FileInfo[] taskFiles = taskDirectory.GetFiles("apples*.xml");