Wildcard variable in file path .. check for file exists?

Hello!
I have a file that I need to check if it exists but it run at various minutes and the folder it is located under is todays date and hhmmss… I know it will run at 6 am but the hh and mm will vary, how do I check for its existence using a wildcard in the file folder path for hh and mm . The file is always called input.txt but saved once a day under the different times but always in the 6 am hour

Hi @hannahscott216

Try this

fileExists = Directory.GetDirectories("YourBaseFolderPath\" & DateTime.Now.ToString("yyyyMMdd") & "\", "06*") _
           .Any(Function(folder) File.Exists(Path.Combine(folder, "input.txt")))

Regards,

1 Like

Hey @hannahscott216
You can try this flow:

  • directoryPath = "C:\YourFolderPath\"
  • filePattern = "input.txt"
  • todayDate = Now.ToString("yyyy-MM-dd")
  • searchPattern = "06*"
  • files = Directory.GetDirectories(directoryPath & todayDate, searchPattern, SearchOption.TopDirectoryOnly).SelectMany(Function(folder) Directory.GetFiles(folder, filePattern)).ToArray()
  • If files.Length > 0