How to rename .zip file name having date and time

I am downloading .zip file from outlook which has todays date and time and saving it into sharepath. downloading and saving file part is working fine. now I need to unzip this file so that I can use that into script. also rename it with below mentioned desired name.

original File name : ALL_New_Details_2023-09-26-13.35Hr.zip
desired name : ALL_New_Details_2023-09-26.zip

Help is much appreciated

Welcome back to the forums @siddhi.kamble!

Step 1: Create the new filename
Use an ‘Assign’ activity and a Regex.Replace to remove the time in the filename.
Left Assign:
str_CleanFilename (new string variable)

Right Assign:
System.Text.RegularExpressions.Regex.Replace(yourZipStr, “.\d{1,2}.\d{1,2}[A-z]{2}(?=.zip)”, “”).ToString

Preview the Regex pattern here
image

Step 2: Rename the file
Then just use the appropriate move/copy/rename activity.

From/ Current filename:
yourZipStr

Destination/New filename:
str_CleanFilename

Hopefully this helps,

Cheers

Steve

Hi,

Can you try as the following?

System.Text.RegularExpressions.Regex.Replace(System.IO.Path.GetFileNameWithoutExtension(filename),"-[^-]+$","")

Sample
Sample20230927-1L.zip (2.6 KB)

Regards,

Hello @Yoichi @Steven_McKeering , thank you for your reply.

i tried both of the mentioned solutions but its still not working also not getting any error.

please note that i’m downloading & saving file at this sharepath : \rpa\Dev\VDI_Inventory_from_all_Locations\ALL_VDI_Details_2023-09-26-13.35Hr.zip

Also i want date to be dynamic as it will change daily receiving file on mail

HI,

To isolate cause, can you try RenameFile activity without variable as the following?


(Please replace ¥ with \ It’s culture info matter)

If it doesn’t work, it’s necessary to find other way.

Regards,

Hey @siddhi.kamble

Try this Regex pattern to simply remove the “dash and time”.
System.Text.RegularExpressions.Regex.Replace(yourZipStr, “-[^-]+(?=\.zip)”, “”).ToString