I’m trying to complete “Building Bot Tasks with RPA Express” course and currently working on Assignment 8. I’m stuck on the step where I need to change the name of the file. Could you please help me figure out how to change the name of the file? What actions, should I use to reach this goal?
Hi @yuliya_harshJZ there is no a file rename option in the actions, but as a workaround you can use the following actions to achieve this goal:
- Read File to save the whole contents of the file to a variable
- Create a File to create a new file with the name you choose (according to the task)
- Write to File to write the contents of a variable to a new file
- Delete File to delete old file
In the end, you will have a new text file with the required name and the same content.
Hope this helps
Thanks for the reply and the workaround. However it’s still not entirely clear to me how I can specify the name of the file (step 2 in your solution) so that it had part of the name of already existing file. Let me support my question with the example:
I have a file named test.txt and need to add current date at the end of the file name. Following your idea, I should add an action to create a file, manually specify the name of the file and add a variable with the current date at the end of the name. Suppose I have 5 files in the folder. Again, following your approach, I should repeat above steps 5 times. Suppose I have 100 files in the folder. In that case I should manually specify the name of each file in the “Create file” action.
That doesn’t seem like an automation to me. But I might be misinterpreting your solution.
Please let me know if I understood you correctly and your approach is expected in the Assignment 8.
Thank you in advance
@yuliya_harshJZ you needn’t do it manually.
You can read the whole contents of the folder into a list using Get Folder Contents action, and then use For Each loop to iterate through the list and perform the same actions for all files in the folder.
You shouldn’t define the name manually, you can define it using variables that will store different values for each file.
You can get the name and extension of the file using Substring between action and save them to a variables and then modify it as required in the task, and you can get the current date using Constant value action and then convert it into a string.
Then you can use these variables to define the new name.
It doesn’t matter how many files you will have in the folder. These actions will create a different new name for each file.
This is an additional optional task, so it is a bit tricky and more advanced than the rest of the assignments.
Ah yes, now it definitely makes sense. Thanks for the detailed explanation!