lundi 18 novembre 2019

How can I get all files that fit a search pattern in c#?

I'm trying to get all files that fit a specific pattern. The file names are comprised of 3 elements which I will refer to as x, y, and z (all are numbers).

X is generally 5 digits long. Y is generally 1 digit long. Z can be up to 2 digits long.

For this example, x = 65986 and y = 1.

I want to get all the files that fit this pattern: "65986_1_Z.csv" where Z can be any digit between 1 and 100 (exclusive).

This is what I currently have:

FileInfo[] files = di.GetFiles(x + '_' + y + "_*.csv");

This somewhat works in that I can get all the files from 65986_1_1.csv to 65986_1_9.csv, but once that final value becomes 10 or greater, this search pattern does not return those files where z > 10.

Am I misusing the '*' wildcard or is there something else I'm doing wrong here?

Aucun commentaire:

Enregistrer un commentaire