Save a file in count form

Hi people

I have a file being saved from the web, I want to save it in count form, for example.

I saved the first time and I want to save it by putting the last number in the count form, the file name is 2021_06_, I want to put a number at the end to show the count, for example 2021_06_1 second time, save 2021_06_2
the third time you save 2021_06_3, always count the last number.

The variable I’m using is this,

datetime.now.adddays (-now.day) .tostring (“yyyy_MM_”)

I just need that after the last “_” comes the count, would anyone know how?

the file is being saved in computer folders

image

1 Like

Hi @Guilherme_Silva

Please read this topic it will be useful for you

And you will find the solution in this topic

2 Likes

HI @Guilherme_Silva

We can use Move file activity here

Here you go with a xaml
changefilename.zip (8.3 KB)

Cheers

1 Like

could you tell me how I add the count to this variable datetime.now.adddays(-now.day).tostring(“yyyy/MM/”) ?

1 Like

could you tell me how I add the count to this variable datetime.now.adddays(-now.day).tostring(“yyyy/MM/”) ?

it’s possible ?

its just string concatenation like this

datetime.now.adddays(-now.day).tostring(“yyyy_MM”)+“_”+count.ToString

Cheers @Guilherme_Silva

1 Like

@Guilherme_Silva - To get yyyy MM format…you can try the below simplified code…

image

1 Like

yes, I’ve already got this part here… but I’m still in doubt here, how to make the counter change the name to 2 or 3, after the first one, to follow the order…

Do I need to use “for each” activity?

@Guilherme_Silva - I see two solution already from Palaniappan and Varun …have you tried that? If yes what error you are getting?

1 Like

you want to change the file name of same file one after the another or you have different files to change in order

Cheers @Guilherme_Silva

1 Like

use stirng.fromat and give {0} to replace that number

I downloaded a file and it comes with a dynamic name, eg name848481
and the other comes under another name850214

so this variable we are creating

datetime.now.adddays (-now.day) .tostring (“yyyy_MM”) + “_” + count.ToString

it’s to count, if it has the ending 1, it puts the 2, etc.

I’m running the tests here, sorry I’m new to uipath and I’m still a little confused

[Palaniyappan]

@Guilherme_Silva - Can you please check this… i guess this might what you are looking for…you have to tweak the code little bit.

Delete Project.Json file and open the Main.xaml file
@Guilherme_Silva

I think, I see what is going on here…everytime when you add the count files count in the folder also increases. So when you loop next time you will get both the files…so we have to take recent file and extract the count from it and then add +1 to it…

Give me sometime. i will develop the workflow and share it…

1 Like

gave this error

Move File: The file already exists.

Thank you very much,

can I make a variable out of it?

datetime.now.adddays (-now.day) .tostring (“yyyy_MM”) + “_” + (counter + 1) .ToString

does this return 2021_06_1, da to let it go to 2 and 3 alone, after reading that 1 already exists?

is this possible or is it more difficult ?

@Guilherme_Silva - here you…I guess it should work for your case… :crossed_fingers:

  1. 1st Run - No files available in the below folder…

image

So below is the output…

image

Now…my code will copy the file from input folder(you can put your download activity here) and rename it to

image

image

  1. 2nd Run - Since there is file exist in the folder…I will look for a recent file based on the create time and extract the counter value from the recent file…and then using Copy file activity(Add your download activity here) I am renaming it.

image

  1. 3rd run…

image

XAML :
MoveAndRename_GS.zip (47.7 KB)

Note: I have removed all the files from the OutputFiles folder. Run the workflow as is and you will see how the file gets created in the outputfiles folder. Once you understood what is happening. You can easily tweak this workflow as per your need.

Hope this helps…

Wow thank you very much!!!
is something that I have not put will be?