FileSystemGlobbing - how to filter files based on timestamp in filename

I have a storage bucket with files that have a date in their filenames



I want to use “List Storage Files” to show only those files that are older than a certain date. This is so that I can delete files that are older than x number of days.

I see there is an option to use “Filter” that accepts a Microsoft FileSystemGlobbing Matcher.

How can I use this Filter to show me only files that are older than X days?


The filter would work only on names and not on the creation date or so…

So as you know the cut off date…in a loop you can list the files based on date and for each date delete the files till you dont find any old files in it…

"File-" + Now.adddays(-5).ToString("dd-MM-yyyy") + -10-30-00.txt"

But if you want to delete previous year or previous month then you can use filter as below without date

"File-*" + Now.addmonths(-1).ToString("MM-yyyy") + -10-30-00.txt"

This will returm all the precious month files …increase the number to get older as well


Thanks @Anil_G

On the same lines is there a way we can specify a range of dates as a regular expression?

That way, I can specify to list all files starting from Day 1 to Day 10 etc

Listing previous month will help to a certain extent too; though ideally I want to delete files older than 5

we could use a LINQ and filtering on a date range. The datetime wi can convert by using the date info string grabbed with a regex


In the filter expression you cannot use regex it supports only few characters like * ? not whole regex


kindly note: agreed to

the given answer

was scoped to: List Storage Files without filter

1 Like

@ppr Would be keen to know the LINQ solution. Appreciate if you could provide an example snippet?

could go in direction like this:

Quick Dirty Regex pattern:

strPattern = "[\d-]{19}(?=\.txt)"
FilterDate | DateTime = now.AddDays(-5).Date

arrFiles | List(Of StorageFileInfo) =

(from x in ListStorageFilesOutVar
Let f = x.FileFullPath
Let s = System.Text.RegularExpressions.Regex.Match(f,strPattern).Value
Let d = DateTime.ParseExact(s, "dd-MM-yyyy-HH-mm-ss", System.Globalization.Cultrueinfo.InvariantCulture)
Where d <= FilterDate
Select v=x).toList

okay, with this solution I have to be okay with first listing all the files in the Storage Bucket.