Save files with an incremental index

Hello,

I have a use case where I need to save info from a website into a Word document daily.

Since the Bot is supposed to run more than once during the day, it should be able to save the word document with the naming: projectName-date-1, projectName-date-2 …
I thought the system would understand if a file with the same name exists and would automatically save the next file with an incremented nr, but there is no such activity apparently?

Is it a way to keep track of this index number?

Thank you in advance.

Hi @armi_v

  1. Create a separate file, let’s call it “counter.txt” to store the current index number. This file will contain a single number that represents the current index.
  2. At the beginning of your bot’s script, read the index number from “counter.txt”. If the file doesn’t exist initially, assume the index number to be 1. After reading the current index number, increment it by one to get the new index.
  3. When saving the Word document, use the projectName-date-index format for the filename. Replace “index” with the value of the new index obtained in step 2.
  4. After saving the Word document, update the “counter.txt” file with the new index so that the next time the bot runs, it knows which index to use.

Hope it helps.

@armi_v

ProjectName-Now.ToString(“yyyy-MM-dd HH:mm:ss”)

This syntax will not need any incrementor. It automatically creates file

@armi_v

Use can also use assets in place of document and increment the counter value in asset by set activity.

@armi_v

  1. Create an Integer type Asset in UiPath Orchestrator to store the index value.
  2. Initialize the index value in Orchestrator with the initial value you want (e.g., 1) when setting up the Asset.
  3. In your UiPath workflow, use the “Get Asset” activity to retrieve the current value of the Asset (index).
  4. Increment the retrieved index by 1 to get the next index value.
  5. Use the incremented index to save the new Word document with the appropriate naming convention.
  6. After successfully saving the Word document, use the “Set Asset” activity to update the Asset in Orchestrator with the new index value.
1 Like

Hi @armi_v

Use the assets to increment the index number.
=> Create a asset in the Orchestrator with the datatype of integer.
=> Use the Get asset activity to get the index from the orchestrator then use the index number to save the file.
=> After that increment the index number by 1.
=> Use the set asset activity to set the value to the same asset.

Then in the second run it will take the second index number.
image

Hope it helps!!

Thank you, I followed these steps and tested it and now it works :slight_smile:

1 Like

Thank you @armi_v

Happy Automation!!

Btw, is there any way to reset the Asset value daily?
So it starts at value 1 every day?

Then do a small project to change the asset to 1.
Trigger this small project at the end of the day.

It will take just 2 seconds.

Hope you understand!!

1 Like

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