I’m trying to find a specific file with a specific modified date in a specific directory. I am currently able to get the latest file in the directory with this snippet: Directory.EnumerateFiles(JsonConfigOut(“NetworkDrive”).ToString(),JsonConfigOut(“ProjectIDInputFile”).ToString,SearchOption.TopDirectoryOnly).OrderByDescending(Function(x) New FileInfo(x).CreationTime).Take(1)
However, is there a way to modify this so I can get a file with a specific modified date?
Use for each file in dictionary then use
File.GetLastWriteTime(path).ToString and Check in which format you are getting the date time then be use the same format as
File.GetLastWriteTime(path).ToString.contains(yourinput)
Thanks Divyashreem! This seems to be taking be down the right path. Is there a way to add a wildcard to this? The reason I ask is because the filenames are appended with a timestamp (see example below).
\DBPWCWYFS05\PCFDataTechInv\Report 52 - SDLC Cap Report Summary2018-05-17-00-30-47.xlsx
Or is there a way to do it with the filename as opposed to the modified date (whichever is easier):
If filename contains Report 52 - SDLC Cap Report Summary Then
See if filename contains specified date
End If
You can use modified date or date in filename, but date in filename would require some date extraction and conversions in order to compare with your date you want to look at.
What if you simply just pulled in the files that match a keyword pattern with a wildcard, then you can either compare the WriteTime with a .Where() or using a For each with an If activity inside.
It might look like this:
Assign dateSearch = "10/20/2018"
Assign filePattern = "Report 52 - SDLC Cap Report Summary*.xlsx"
Assign dir = "\\DBPWCWYFS05\PCFDataTechInv"
Assign fileSearchList <Array of String> = Directory.GetFiles(dir, filePattern).Where(Function(f) File.GetLastWriteTime(f).ToString("MM/dd/yyyy") = CDate(dateSeearch).ToString("MM/dd/yyyy") ).ToArray
If fileSearchList.Count > 0
<perform tasks on fileSearchList.First>
Option of using For each would replace the fileSearchList assignment slightly, like this:
Assign fileSearchList <Array of String> = Directory.GetFiles(dir, filePattern)
For each file in fileSearchList
If File.GetLastWriteTime(f).ToString("MM/dd/yyyy") = CDate(dateSeearch).ToString("MM/dd/yyyy")
<perform tasks on file>
Break
Or something like that…
If these ideas interest you, and you run into problems paste some screenshots of what you are working with and maybe we can identify some solutions for the errors.