Automation Anywhere's Bot Store has an awesome collection of freely available bots and packages. In this tutorial, we'll take a look at setting up and using the File and Folder Attributes Package. This tutorial can be followed if you're using Community Edition or Automation 360 Enterprise - so follow along so your bots can know more about the files and folders that you work with.
File and Folder Attributes Package
It's not uncommon for an automation use case to include the need to manipulate, modify, and iterate through files. When those situations come up - it can be important to validate that the file you're about to make modifications to is the actual file you intend to modify, and not another file found within the folder. This comes up frequently in situations where you need to find the newest file in a directory, need to delete the oldest file in a folder, or you're looking for the smallest file but don't necessarily know the name. The best way to be sure you're working with the correct file in these situations is by validating the extended properties of the said file using the File and Folder Attributes package available in Bot Store.
If you want to follow along with the tutorial above, you can download the sample bot that Micah is using in the screen share to replicate the examples he's demonstrating.
Upon pressing the Get Bot button on the Bot Store listing page, users are presented with the option of downloading a zip file locally (works for Community Edition or Enterprise Edition) or installing the package directly onto their Control Room (works for Enterprise Edition only). The video above walks through the process of downloading the package locally as a zip file, then upload it into the respective environment where the package is needed. This is the cleanest process to follow as it works for both Community and Enterprise editions.
To install/upload the package to your environment, login to the Control Room, navigate to the Automations tab, and press the Import Bots.. button in the top right corner of the Automations screen. This will enable you to upload the recently downloaded zip file and install it into your environment. Note: this process may take some time based on your internet speeds and the size of the package you are uploading, so be patient if it takes more than a second or two.
Files in Folder Deep
The Files in Folder Deep action takes a directory path as input and will output a list of all files contained within the provided directory (including all subdirectories as well). This can be an extremely fast way to quickly iterate through a full directory structure without having to do multiple levels of loops/nested loops. Using the built-in loop package, developers can easily use the list that is returned as the output of this action to get the file properties for every file within a large directory.
The File Attributes action takes the full path to a file as its input and returns a dictionary (key-value pairs) of various file properties from the provided file. Based on the type of file selected, these properties may change slightly:
- If the file is a PDF, the returned dictionary will include height/width of the first page of the document, as well as the total count of pages that the PDF contains.
- If the file is a png, bmp, jpeg, the returned dictionary will include the height/width of the image.
For all files, the action will return attributes like the file's owner, modified date, file size (in btyes), extension, file name, path, read-only, hidden, etc.
Files in Folder
For situations where you don't need the files contained within all subfolders, consider using the Files in Folder action. The Files in Folder action takes two inputs: the path to the directory for analysis, as well as the sorting method that should be used for the returned list. The returned value from this action is a list, sorted by date (desc/asc), name (desc/asc), or size (desc/asc). This action is particularly useful when a bot needs to identify the smallest or newest file within a directory without the need for additional looping.
The Folder Attributes action is similar to that of the File Attributes action - except in this case the input expected is a path to a directory (not a file itself). Like the File Attributes action, the Folder Attributes action will return a dictionary of attributes - with key/value pairs that are slightly different than seen on the File Attributes - to include properties like count of files, total folder size, count of subdirectories, etc.
Folders in Folder
The Folders in Folder action will return a list of all folders (excluding files) found within a provided directory. This list will only contain the folders found directly within the provided directory path, and will not include subfolders of each found subfolder. This can be helpful for situations where developers need to iterate through each folder found within a directory structure and don't want to use the File in Folders Deep action.
Bot Store provides Automation Anywhere users with a host of additional packages that can be explored and used to automate their identified manual tasks. The File and Folder Attributes package is a great example of a utility package that adds value for those who are automating use cases that deal specifically with the manipulation/movement of files found within a local or network directory. For those interested in digging even deeper into this package, check out the full source code of the package available on the Automation Anywhere GitHub page.