Downloading, renaming and moving files

Hello

I have built a workflow which inputs data in the browser and then downloads a csv file in the downloads folder. This is done multiple times, thus resulting in multiple separate files. I use a for each activity and have managed to download them and move them as a bulk in to the end folder. However, this is not exactly what I’d like to happen.

I need to rename each file after the download and then move them to the end folder. Basically the new name would need to be like this:

new_name = old_name + item from an array + “text” + “item from an array

What is the most suitable way to do this?

Hi @Topias_Stromberg
Welcome to forum

Since you are downloading and put in the download folder

and after itertaing through each of it
iniside the loop, use move file activivty with providing old path and new path again with new file name

or

Another way is instead of placing in download folder and moving in end folder

better way would be downloading the file into that endfolder directly

For that u had to do some settings in the chrome/web browser u are using

For chrome check as below

Then u can put the full path in save as dialog box and click on save button directly

This would be much faster

Hope it help you

Regards
Nived N
Happy Automation

1 Like

Use directory.get file, Torename the file you have to use getfilenamewithoutextention()

Hi @Topias_Stromberg, you can use the move file activit to rename the file
E.g
Array_files =Directory.GetFiles(“folderpath”,”*.pdf”).
Use a for each loop to get all files name , then use a move file activity to rename your file. In move file activity provide the old path and destination path with new name.

Thank you for the reply.

I got the move file activity to work to some extent. Meaning I can move the files but can’t rename them in the way I would like to. I have an array of strings which I am inputting to the website. Each iteration results in a new csv file and I would like to name each file with the corresponding items in that array.

What should I put in the “to” field in move file? Currently I’ve tried this:

To = destinationfolder + "" + item + “text” + item + “.csv”.

The item is because I’m operating inside a for each loop. However, this approach is not working.

Topias

Hi @Topias_Stromberg

what error u are getting?

Thank you for quick response. However I managed to go around that one. Not pretty but it works :slight_smile:

Now I am trying to work with the csv files and reshape the data to be in more than one column. Any tips on that one?

Topais

Hi @Topias_Stromberg

It is possible

What u need to do is

  1. Read the CSV file and store in dt1

  2. Then use invoke code activitiy with language type as c# and passing dt1 as in/out argument and use the below code

dt1.Columns.Add(columnName)

Now use write CSV file to write the updated datatable in csv

U can see one more column is being added to it !!

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed:

Thank you. I realized I was a bit unclear what I am doing with the csv files. Currently it has everything in one column with comma as a separator. I need to reform it using the Text to columns feature in excel.

Got this done for one file.

I’m using directory.getfiles activity to store all the file paths into a “my_variable”. Then in a for each activity I have “ForEach item in my_variable”. Then a read csv activity and write range activity. However, this only generates one new file. I have no idea why it stops there?

@Topias_Stromberg - Could you please show us the screenshot of your workflow?

File Handling.xaml (7.5 KB)

So, what I am trying to achieve here: I have the downloaded files in the folder “CSV” and in those files all the data is in the column A, thus I need to do something similar than “Text to columns” in Excel. With getfiles I assign all the filepaths into the variable filesNames. Then I use readcsv activity in for each and create datatables. Then, I want to create new excel files into a new folder called “EXCEL”. The variable “helperNumber” is used to file naming purposes only.

By running this workflow I only get one file to the EXCEL folder and then it stops.

@Topias_Stromberg - Please check this…FileHandling.zip (173.2 KB)

Here I have read the CSVs from the folder and saved as Excel files. As you can see all the files got converted successfully.

Thank you @prasath17 this worked. Care to enlighten me what was wrong with my initial try?

@Topias_Stromberg - I guess, it may be problem with the HelperNumber. I didn’t get a chance to debug to be honest since I need to change the paths.

If its solves your query, please mark my post as solution, that will close this thread.

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