Get file dynamic

Hi all,

Software export 2 file:
ARR013_yyyyMMddhhmm_USD.xlsx.xlsx (want get)
ARR013_yyyyMMddhhmm(.)_USD.xlsx.xlsx (no)

I assigned it as below but not correct. How can I get the correct file?

Directory.GetFiles(“D:\RPA\UiPath\ACC\ARR File"+DateTime.Now.ToString(“yyyyMMdd”)+”",“ARR013_*_USD.xls.xlsx”)

Hi @anh.nguyen
Try this:

Directory.GetFiles("D:\RPA\UiPath\ACC\ARR File\" + DateTime.Now.ToString("yyyyMMdd"), "ARR013_*_USD.xlsx.xlsx")

This should match files with names like “ARR013_yyyyMMddhhmm_USD.xlsx.xlsx” as you mentioned you want, and exclude files with “ARR013_yyyyMMddhhmm(.)_USD.xlsx.xlsx” as you mentioned you don’t want. Just make sure you replace “yyyyMMdd” with the actual values you need to match the desired timestamp format.

Hope it helps!!

It can’t find file

@anh.nguyen

Give the write line acitivty inside the for each loop and pass the item in that. Check whether it’s getting printed.

Regards

@Parvathy

@anh.nguyen
Try this:

Directory.GetFiles("D:\RPA\UiPath\ACC\ARR File\" + DateTime.Now.ToString("yyyyMMdd"), "ARR013_*_USD.xls.xlsx")

Regards

1 Like

May be use RegularExpression


Directory.GetFiles("D:\RPA\UiPath\ACC\ARR File" + DateTime.Now.ToString(“yyyyMMdd”))

System.Text.RegularExpressions.Regex.IsMatch(currentItem,“ARR013_[0-9]{12}_USD.xls.xlsx”)

1 Like

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