-1

I have a method that watches a folder and checks if a file exists. Once the file exists, some code will execute handling the file.

The file name has the form DailyReport_MMddyyyy_[some sequence of numbers].xlsm. The MMddyyyy part is a date in that form (so i.e. 08132014 for 08/13/2014), and the sequence of numbers has to do with the time the report is generated and is unimportant for my purposes. This report is generated once a day, so the part of the file name that I'm interested in is up to the MMddyyyy part.

Is there a way to indicate "variable" characters in a string? I.e. var filename = "DailyReport_" + DateTime.Now.ToString("MMddyyyy") + "[something to indiciate any variable number of characters]"? Right now I am using File.Exists(filePath) to check if the file exists every few minutes with Quartz scheduler.

user2424607
  • 295
  • 3
  • 19
  • 1
    How about: fileName.StartsWith("DailyReport_") && fileName.EndsWith(".xlsm") – Ian P Aug 13 '14 at 20:19
  • regex is the generic answer – pm100 Aug 13 '14 at 20:19
  • Great news, this has already been answered in another stack overflow question [right here](http://goo.gl/W9MO7X) – clarkitect Aug 13 '14 at 20:19
  • possible duplicate of [file exists by file name pattern](http://stackoverflow.com/questions/1199260/file-exists-by-file-name-pattern) – clarkitect Aug 13 '14 at 20:20
  • When you say "indicate 'variable' characters in a string", do you mean "variable characters in a filename I'm search for"? – James Curran Aug 13 '14 at 20:20
  • @JamesCurran: I mean, I don't know what the variable characters will be, but I don't care. I just want to find the file with the name `DailyReport_[today's date here]` and don't care about what the `_[random numbers here].xlsm` part. – user2424607 Aug 13 '14 at 20:22
  • @user2424607: You keep talking about "characters in a string". the string is irrelevant. What you actually want to do is "search for a file when I only have a partial name". Pose the right question, and you get better answers. – James Curran Aug 14 '14 at 13:56

1 Answers1

0

You could use string.format. Like so,

string filename = string.Format("Hey, {0} it is the {1}st day of {2}.  I feel {3}!", _name, _day, _month, _feeling);
killQuotes
  • 178
  • 13
  • I mean, I don't know/care what the variable characters will be. I just want to find the file with the name `DailyReport_[today's date here]` and don't care about what the `_[random numbers here].xlsm` `part. – user2424607 Aug 13 '14 at 20:26
  • I see. My thought was using string.format would allow you to use the '{0}' to act a a placeholder for [today's date] part of the filename. I misunderstood what you were asking. – killQuotes Aug 13 '14 at 20:36