I want to learn and know, how to use the Assign activity properly instead of hardcoding.
Example:
ReadDirecPath = Directory.GetFiles() ← What do I input inside GetFiles for and what else can I input here ?
I know i can use Assign to assign a variable to a string, but when it comes to data manipulation or transformation, I do not know what type/data/format i can use Assign activity for.
Can anyone explain or show me a link for guidance?
You can pass the Folder path into a variable and then pass that variable in between the brackets.
ReadDirecPath should be an String() → [Array of String].
The readDirecPath is array of string because it contains all the files in that for and later use and for each activity and loop that ReadDirecPath and you can go through each file.
Please refer the below steps for better understanding:
Here’s how you can use the Assign activity to make the workflow more flexible:
Create a variable for the text file path:
In UiPath Studio, go to the Variables panel and click Add Variable.
Name the variable TextFilePath.
Set the variable type to String.
Assign the file path to the variable:
Drag an Assign activity onto the workflow designer.
In the To field, enter TextFilePath.
In the Value field, enter the path to your text file. You can use double quotes (") to specify the path. For example, @"C:\Users\username\Documents\myfile.txt".
Use the variable in the Read Text File activity:
Replace the hardcoded path in the Filename field of the Read Text File activity with the TextFilePath variable. You can use the UiPath expression builder to access variables. Just type a dollar sign ($) followed by the variable name (e.g., ${TextFilePath}).
This way, you can change the text file path by modifying the value assigned to the TextFilePath variable. You don’t need to modify the workflow itself.
You can use similar techniques to create variables for the output CSV file path and other options in the workflow.
The Directory.GetFiles() method can be used to get a list of files in a directory. You can use the output of this method to dynamically select a text file to read. However, this is beyond the scope of the screenshot you provided.
For more information on using the Assign activity and UiPath expressions, you can refer to the UiPath documentation on UiPath Assign activity
there is no specific need for it…but if you give absolute path of any file inside your project then it might be an issue
as when running from orchestrator the package will be downloaded to a different location and if you select a file in the project folder then the file you selected might not be used as expected as the package file will be in a different location
for example when you develop process the project resides mostly in documents folder but when running from orchestrator the project does not reside in documents rather in the user folder under .nuget
Code with assigned paths is easier to understand and maintain. You can see the exact location you’re working with directly in the code. Clicking activities require you to look at the designer view to understand the target folder…
Assigning paths allows for better error handling. You can validate the path exists before using it in your workflow. Click activities might fail silently if the target element is not found.