Validate for File naming scheme

46 views Asked by At

I have a file that drops into a folder location. I'm looking for a file named like this.

ID _Data_Tape_CCYYMMDD_hhmmss.txt

How do i accomplish this?

1

There are 1 answers

1
Óscar López On BEST ANSWER

How about using a regular expression? in Racket, this will match the given file name:

(define name "42_Data_Tape_11220331_234532.txt")

(regexp-match #px"\\d+_Data_Tape_\\d{8}_\\d{6}.txt" name)
=> '("42_Data_Tape_11220331_234532.txt")

(regexp-match #px"\\d+_Data_Tape_\\d{8}_\\d{6}.txt" "something-else")
=> #f

To list all the files in a directory use directory-list or an equivalent procedure in your interpreter, then match their names against the above regular expression - and there, you found the files with the expected name.