Creating a Variable

HI!

I have the following path C:\Users\XXXXX\Downloads. The xxxxx represents my variable. How do I create a variable for this?

Also if I have a .csv file on this folder called example.csv and everyday I create the same file on that same folder without deleting the old one this will create example(1).csv, example(2).csv and so on. How can I create a variable to choose the latest file with that name on the folder?

Hi,

Do you need the above path as variable? If so, the following will help you.

Let’s say yourString=“xxxxx”

Then

System.IO.Path.Combine("C:\Users",yourString,"Downloads")

Or the following might work.

System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("USERPROFILE"),"Downloads")

Regards,

Hi,

Let’s say files = System.IO.Directory.GetFiles(yourPath)

Then

targetFile = files.OrderBy(Function(f) if(System.Text.RegularExpressions.Regex.IsMatch(System.Io.Path.GetFileNameWithoutExtension(f),"\d+(?=\)$)"), Int32.Parse(System.Text.RegularExpressions.Regex.Match(System.Io.Path.GetFileNameWithoutExtension(f),"\d+(?=\)$)").Value),0)).Last()

Regards,

Directory.GetFiles(YourFolder).OrderbyDescending(Function(F) New FileInfo(F).CreationTime).First()

Thank You all for your responses.

Here is the scenario. I am using the Excel Application Scope.

I want for Excel to pull the latest .xlsx file from the downloads folder. On the workbook path if I use the answers you provided me I have a end of expression error. How should I use it to pull the latest .xlsx file from the downloads folder? I believe that using the (USERPROFILE",“Downloads”) helps me a lot with the path but I am not sure that if in this activity this works or not.

Also on the bottom where I can see variables can I have more than one variable there for an activity or process?

Hi,

Can you share your workflow?

Regards,

HI!

I can’t share my workflow since it is from my work computer but based on your response I am replacing the workbook path on the Excel Activity scope with this previous expression you provided ( leaving it as you provided it goes and look on the folder for a downloads.xlsx file which is not correct. I then tried adding the expression below but still does not work)the system can’t validate it. It gives me an end of expression expected error.

This is the expression

System.IO.Path.Combine(System.Environment.GetEnvironmentVariable(“USERPROFILE”),“Downloads”)

System.IO.Path.Combine(System.Environment.GetEnvironmentVariable(“USERPROFILE”),“Downloads”, “.xlsx”)

Hi,

Hope the following sample helps you.

Main.xaml (7.5 KB)

Regards,

HI!

First let me tell you that this worked flawlessly on my personal computer which is running UiPath on a virtual machine. I only had one Excel file on that machine and found it and opened it without issues.

On my work computer I have several Excel files. Some of them had the same name and at the end of the file name there is a (1). For some strange reason this were the files that it was choosing to open that were not the last modified file on this folder. Do you have an idea of why?

I tried deleting the file it was picking up but it automatically went and used the next one that was found with that same (1) at the end.

Also I need to keep the Excel file open. I know there is a checkmark that you can state to leave it open but on my version this checker on that option does not exist. Do you have any recommendations on how to keep it open?