-1

I have some files that name are ABC-randomcode.zip,ABC-randomcode.mov and etc.

I use this code to find all file which started by ABC but it does not work!

var textFiles = Directory.GetFiles("E:\\000", "*.*", SearchOption.AllDirectories).Where(s => s.StartsWith("foldername-"));

its not my problem . My target is to select some file that starts with a unique string like ABC.

ingvar
  • 4,169
  • 4
  • 16
  • 29
D.JCode
  • 386
  • 2
  • 12

1 Answers1

3

Just add foldername- to your search pattern:

var textFiles = Directory.GetFiles("E:\\000", "foldername-*.*", SearchOption.AllDirectories);

From docs:

The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.

Link

ingvar
  • 4,169
  • 4
  • 16
  • 29