Class Resource

java.lang.Object
com.workfusion.rpa.helpers.Resource

public class Resource extends Object
This class adds static methods for work this file system.

Driver Type: Desktop

  • Method Details

    • exist

      public static boolean exist(String path)
      Check if file or directory exists

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory.
      Returns:
      boolean representation of resource existence
      Example
      def filePath = 'D://temp//whokilledkennedy.docx'
      boolean exist = Resource.exist(filePath);
    • delete

      public static boolean delete(String path)
      Delete file or directory

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory.
      Returns:
      boolean representation of operation success
      Example
      def filePath = 'D://temp//whitneses.docx'
      boolean deleted = Resource.delete(filePath);
    • createFileOverwrite

      public static boolean createFileOverwrite(String path)
      Create new file. Overwrite, if file already exists

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory.
      Returns:
      always returns true
      Example
      def filePath = 'D://temp//whitneses.txt'
      boolean created = Resource.createFileOverwrite(filePath);
    • createFileSkip

      public static boolean createFileSkip(String path)
      Create new file. Skip, if file already exists

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory.
      Returns:
      boolean representation of operation success. True - new file was created. False - file already existed
      Example
      def filePath = 'D://temp//takeovertheworld.pptx'
      boolean created = Resource.createFileSkip(filePath);
    • createFileFail

      public static boolean createFileFail(String path)
      Create new file. Fail with exception, if file already exists

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory.
      Returns:
      boolean representation of operation success
      Throws:
      org.openqa.selenium.WebDriverException - if file already exist
      Example
      def filePath = 'D://temp//takeovertheworld.pptx'
      boolean created = Resource.createFileFail(filePath);
    • listFolder

      public static List<String> listFolder(String path)
      Lists directory contents of files

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      Returns:
      list representation of full path to files in specified directory
      Example
      def filePath = 'D://temp'
      List folderContent = Resource.listFolder(filePath);
    • listFolder

      public static List<String> listFolder(String path, Filter filter)
      Lists directory contents using spcial filter

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      filter - Filter
      Returns:
      list of full path to filtered files or/and folders in specified directory(and subdirectories, if specified)
      Example
      def filePath = 'D://temp'
      List folderContent = Resource.listFolder(filePath, Filter.files().pattern('tempFile.*tmp').get());
      See Also:
    • createDirectoryOverwrite

      public static boolean createDirectoryOverwrite(String path)
      Creates new directory. Overwrite, if directory already exists

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      Returns:
      always returns true
      Example
      def filePath = 'D://temp//newDirectory'
      boolean created = Resource.createDirectoryOverwrite(filePath);
    • createDirectorySkip

      public static boolean createDirectorySkip(String path)
      Creates new directory. Skip, if directory already exists

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      Returns:
      boolean representation of operation success. True - new directory was created. False - directory already existed
      Example
      def filePath = 'D://temp//newDirectory'
      boolean created = Resource.createDirectorySkip(filePath);
    • createDirectoryFail

      public static boolean createDirectoryFail(String path)
      Creates new directory. Fails, if directory already exists

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      Returns:
      always returns true
      Throws:
      org.openqa.selenium.WebDriverException - if directory exist
      Example
      def filePath = 'D://temp//newDirectory'
      boolean created = Resource.createDirectoryFail(filePath);
    • read

      public static String read(String path, String encoding)
      Reads file content

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      encoding - string representation of file encoding
      Returns:
      string representation of file content
      Example
      def filePath = 'D://temp//newDirectory//file.txt'
      def content = Resource.read(filePath, 'utf-8');
    • overwrite

      public static void overwrite(String path, String value, String encoding)
      Overwrites file content

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      value - string representation of text to overwrite with
      encoding - string representation of file encoding
      Example
      def filePath = 'D://temp//newDirectory//file.txt'
      Resource.overwrite(filePath, 'utf-8');
    • append

      public static void append(String path, String value, String encoding)
      Appends content to file

      Driver Type: Desktop

      Parameters:
      path - string representation of path to file or directory
      value - string representation of text to append
      encoding - string representation of file encoding
      Example
      def filePath = 'D://temp//newDirectory//file.txt'
      Resource.append(filePath, 'added Text', 'utf-8');
    • copyOverwrite

      public static void copyOverwrite(String resourceFrom, String pathTo)
      Copies file or directory. Overwrites if file/directory already exist

      Driver Type: Desktop

      Parameters:
      resourceFrom - string representation of path to file or directory which should be copied
      pathTo - string representation of a copy destination path
      Example
      def resourceFrom = 'D://temp//file.txt'
      def pathTo = 'D://temp//newDirectory//file.txt'
      Resource.copyOverwrite(filePath, 'added Text', 'utf-8');
    • copySkip

      public static void copySkip(String resourceFrom, String pathTo)
      Copies file or directory. Skips if file/directory already exist

      Driver Type: Desktop

      Parameters:
      resourceFrom - string representation of path to file or directory which should be copied
      pathTo - string representation of a copy destination path
      Example
      def resourceFrom = 'D://temp//file.txt'
      def pathTo = 'D://temp//newDirectory//file.txt'
      Resource.copySkip(resourceFrom, pathTo);
    • copyFail

      public static void copyFail(String resourceFrom, String pathTo)
      Copies file or directory. Fails if file/directory already exist

      Driver Type: Desktop

      Parameters:
      resourceFrom - string representation of path to file or directory which should be copied
      pathTo - string representation of a copy destination path
      Throws:
      org.openqa.selenium.WebDriverException -
      Example
      def resourceFrom = 'D://temp//file.txt'
      def pathTo = 'D://temp//newDirectory//file.txt'
      Resource.copyFail(resourceFrom, pathTo);
    • moveOverwrite

      public static void moveOverwrite(String resourceFrom, String pathTo)
      Moves file or directory. Overwrites if file/directory already exist

      Driver Type: Desktop

      Parameters:
      resourceFrom - string representation of path to file or directory which should be copied
      pathTo - string representation of a copy destination path
      Example
      def resourceFrom = 'D://temp//file.txt'
      def pathTo = 'D://temp//newDirectory//file.txt'
      Resource.moveOverwrite(resourceFrom, pathTo);
    • moveSkip

      public static void moveSkip(String resourceFrom, String pathTo)
      Moves file or directory. Skips if file/directory already exist

      Driver Type: Desktop

      Parameters:
      resourceFrom - string representation of path to file or directory which should be copied
      pathTo - string representation of a copy destination path
      Example
      def resourceFrom = 'D://temp//file.txt'
      def pathTo = 'D://temp//newDirectory//file.txt'
      Resource.moveSkip(resourceFrom, pathTo);
    • moveFail

      public static void moveFail(String resourceFrom, String pathTo)
      Moves file or directory. Fails if file/directory already exist

      Driver Type: Desktop

      Parameters:
      resourceFrom - string representation of path to file or directory which should be copied
      pathTo - string representation of a copy destination path
      Throws:
      org.openqa.selenium.WebDriverException -
      Example
      def resourceFrom = 'D://temp//file.txt'
      def pathTo = 'D://temp//newDirectory//file.txt'
      Resource.moveSkip(resourceFrom, pathTo);