Rename a Directory (Folder) in UiPath using Invoke Code and Invoke Method
Hi Welcome to another post of Codehunters.
In this post we will see how we can rename a folder in UiPath.
Let’s Start.
I have a folder named Documents, and I want to rename it with Processed Documents.
There are two ways we can rename a Folder in UiPath, first is using Invoke Method and another is Invoke code.
Lets use Invoke Method to rename the folder. For that Drag and Drop Invoke Method Activity and in the Target Type click on Browse and search for
Microsoft.VisualBasic.FileIO.FileSystem
If we check the Official Documentation we can see we have a method available for Renaming a Directory called RenameDirectory1, so we will use this method in Method name and we can see it needs two string parameter so provide the two parameter2 from properties panel first will be Old Directory Name with complete Path and the second parameter will be New Folder name, It doesn’t require complete path as it will use the From Path.
Now that’s it, we can run the Bot. The Directory will be renamed to ProcessedDocuments.
In the parameters we can also provide the variable name. Suppose we want to rename the folder to the current date we can type
DateTime.Now.ToString(“DD-MMM-YYYY”)
And run again. It will be renamed as today’s date.
The another way to rename the directory is to Invoke Code.
So lets Drag and Drop the Invoke Code Activity and click on Edit Code and lets type the code
FileIO.FileSystem.RenameDirectory(OldDirectoryName, NewDirectoryName)
and you can see it need two parameters Old Directory and New Directory Name Click on the Edit Arguments and Create two arguments First is OldDirectoryName and NewDirectoryName and give the Path.
Run the Bot again And it should rename the Directory.
So this is how you can rename the Directory in UiPath.
Hope this helps And I will see you in the next Post. Till then Code with Confidence.