Read and Review Automation Anywhere Documentation

Automation 360

Close Contents

Contents

Open Contents

FILE2 (Regex) attribute

  • Updated: 2022/05/19
    • Automation 360 v.x
    • Explore
    • RPA Workspace

FILE2 (Regex) attribute

A regular expressions (RegEx) are patterns of string defined to search for a file in a specified path. Use the FILE2 attribute when using regular expressions (regex) to create string patterns.

For instance: If you want to search a folder path for a file (For example Hello.txt)which contains a certain string. . You will use File2 attribute type to enter the following regex pattern: Hell or ell which will find the file that matches the search criteria. This topic is based on the File2TypeDemo sample available within the Package SDK in the following location <PackageSDK>\src\main\java\com\automationanywhere\botcommand\samples\commands\basic\types\File2TypeDemo.java.

Using the FILE2

  1. Make sure you have imported the following packages to ensure all the functionalities works as described in the sample.
    import com.automationanywhere.commandsdk.annotations.*;
    import com.automationanywhere.commandsdk.model.AttributeType;
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
  2. Add the @BotCommand annotation to make a class as an Action in the Control Room. For more information on annotations, see Annotations.
    @BotCommand
  3. Add the @CommandPkg annotation to define all the UI related components - labels, description, icon, return type, and name.
    @CommandPkg(label = "[[File2TypeDemo.label]]", description = "[[File2TypeDemo.description]]", icon = "sample.svg", name = "file2TypeDemo")
  4. Create a method (For example: regexFile) within your class and define the fields as described below.
    1. Annotate the method with @Execute to execute the method during compilation.
    2. In the below sample, @Idx, @Pkg, and @NotEmpty are defined as a parameters of the method. If they are used as a member of the class, then you should use set and get methods to define them.
      1. @Idx - Defines the index of an action. (@Idx(index = "1", type = AttributeType.FILE2))
      2. @Pkg - Defines all the parameters and member variables shown in the interface (@Pkg(label = "[[File2TypeDemo.localFile.label]]") ). Must be accompanied by the @Idx, if not this annotation is ignored.
      3. @NotEmpty - Defines that this parameter cannot be empty (@NotEmpty @LocalFile FileValue fileValue)).
        @BotCommand
        @CommandPkg(label = "[[File2TypeDemo.label]]",
            description = "[[File2TypeDemo.description]]", icon = "sample.svg", name = "file2TypeDemo")
        public class File2TypeDemo {
            private static Logger logger = LogManager.getLogger(File2TypeDemo.class);
        
            @Execute
            public void regexFile(
                @Idx(index = "1", type = AttributeType.FILE2) 
                @Pkg(label = "[[File2TypeDemo.localFile.label]]") 
                @NotEmpty @LocalFile FileValue fileValue)
  5. Drag the action into canvas and you will be able to input the regex to find a file. You will see an input box similar to this image.

    The image shows Variable SDK Demo

Print the Regex - Folder name and the File location

Use the Logger interface obtained from Log4j package to provide information of the objects being manipulated. In the below sample you will be able to log the folder name and the local file location by using the debug method.

@BotCommand
@CommandPkg(label = "[[File2TypeDemo.label]]",
  description = "[[File2TypeDemo.description]]", icon = "sample.svg", name = "file2TypeDemo")
public class File2TypeDemo {
  private static Logger logger = LogManager.getLogger(File2TypeDemo.class);

  @Execute
  public void regexFile(
    @Idx(index = "1", type = AttributeType.FILE2) @Pkg(label = "[[File2TypeDemo.localFile.label]]") @NotEmpty @LocalFile FileValue fileValue) {
    if (fileValue.isRegex()) {

      RegexFile regexFile = fileValue.getRegex();
      logger.debug("folder name {}", regexFile.getFolder());
      logger.debug("local file location {}", regexFile.getFileNamePattern().toString());
    } else {
      logger.debug("Regex option is not selected");
    }
  }
Send Feedback