VB.Net Regex

Hi all, it has been a while since I asked a question here, I hop all is well, I have a question regarding regex, How can i replace a filenames with dates, now i know how to, i use this vb.net method: fileName.Replace(“.pdf”, now.ToString(“_yyy_MM_dd”) + “.pdf”), however i wish to use the asterisk (*) so that i can replace any filename with the current date. so if the file name is abcdf.pdf i want it to be renamed as New file name:_2020_05_07.pdf, Note, the folder might contain multiple PDF files with different names.

Thank you in advance for the support.

1 Like

Use the Move File activity. When you get the filename, you can move it to destination Now.ToString("_yyyy_MM_dd") + ".pdf".

@Anthony_Humphries Thank you for the solution, how ever i was hoping to get a solution where i could stat that * any character/characters string would be replaced by the date using the Replace method, is this not possible?

It’s possible to do this with regular expressions, but it will make the workflow more complicated. You would need to get the filename (e.g. MyFileName) without the extension and assign a string to the following: System.Text.RegularExpressions.Regex.Replace(MyFileName, "*", Now.ToString("_yyyy_MM_dd")).Value.

However, this is only going to create the string variable with the date, and you will need to append the extension anyway.

5 Likes

@Anthony_Humphries Thank you very much, this is exactly what i was looking for, I really appreciate it.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.