public static String[] getDownloadedFilesFromListByRegExp(
      LaunchedBrowserOnRc launchedBrowserOnRc,
      String[] flList,
      String fileNameRegExp,
      String fileExtention)
      throws Exception {
    if (flList == null || flList.length == 0) {
      return null;
    }

    List rez = new ArrayList<String>();

    String filePattern;
    if (fileNameRegExp == null || fileNameRegExp.length() == 0) {
      throw new Exception("fileName is not specified:" + "\"" + fileNameRegExp + "\"");
    }

    if (fileExtention == null || fileExtention.trim().length() == 0) {
      fileExtention = null;
    }

    BrowserFamily browserFamily = launchedBrowserOnRc.getBrowser().getBrowserFamily();
    if (browserFamily.equals(BrowserFamily.FIREFOX)) {
      if (null != fileExtention) {
        filePattern =
            "^"
                + fileNameRegExp
                + "(\\(\\d*\\))?\\."
                + fileExtention
                + "$"; // ^Tag Library Admin(\(\d*\))?\.xls$
      } else {
        throw new Exception("Files without extention are not supported yet");
        //    filePattern="^"+fileName+"(\\(\\d*\\))?$";// ^Tag Library Admin(\(\d*\))?$
      }
    } else {
      throw new Exception("The browser family is not emplimented yet" + browserFamily);
    }

    for (String fn : flList) {
      Pattern pattern = Pattern.compile(filePattern);
      File file = new File(fn);
      Matcher matcher = pattern.matcher(file.getName());
      if (matcher.matches()) {
        rez.add(file.getName());
      }
    }

    if (rez.size() == 0) {
      return null;
    } else {
      return (String[]) rez.toArray(new String[0]);
    }
  }
  /**
   * Deletes downloaded files related to one file form the specified (browser download) folder e.g.
   * for FireFox: if specify fileName="Tag Library Admin"; fileExtention="xls" files would be
   * deleted: "Tag Library Admin.xls", "Tag Library Admin(2).xls", "Tag Library Admin(3).xls"
   *
   * @param browser
   * @param downloadFolderPath
   * @param fileName
   * @param fileExtention
   * @throws Exception
   */
  public static void deleteDownloadedFiles(
      LaunchedBrowserOnRc launchedBrowserOnRc, String fileName, String fileExtention)
      throws Exception {
    final IRcFileSystem rcFS = launchedBrowserOnRc.getRcFileSystem();
    String filePattern;
    if (fileName == null || fileName.length() == 0) {
      throw new Exception("fileName is not specified:" + "\"" + fileName + "\"");
    }

    if (fileExtention == null || fileExtention.trim().length() == 0) {
      fileExtention = null;
    }

    BrowserFamily browserFamily = launchedBrowserOnRc.getBrowser().getBrowserFamily();

    if (browserFamily.equals(BrowserFamily.FIREFOX)) {
      if (null != fileExtention) {
        filePattern =
            "^"
                + fileName
                + "(\\(\\d*\\))?\\."
                + fileExtention
                + "$"; // ^Tag Library Admin(\(\d*\))?\.xls$
      } else {
        filePattern = "^" + fileName + "(\\(\\d*\\))?$"; // ^Tag Library Admin(\(\d*\))?$					}
      }
    } else {
      throw new Exception("The browser family is not emplimented yet" + browserFamily);
    }

    //			File downLoadFolder = new File(downloadFolderPath);
    //			if (!downLoadFolder.exists()) {
    //				throw new Exception("Download folder doesn't exists:"+"\""+ downloadFolderPath +"\"");
    //			}

    if (!rcFS.exists(launchedBrowserOnRc.getBrowserDownloadFolder())) {
      throw new Exception(
          "Download folder doesn't exists:"
              + "\""
              + launchedBrowserOnRc.getBrowserDownloadFolder()
              + "\"");
    }

    //			if (!downLoadFolder.isDirectory()) {
    //				throw new Exception("Download folder is not a directory:"+"\""+ downloadFolderPath +"\"");
    //			}

    if (!rcFS.isDirectory(launchedBrowserOnRc.getBrowserDownloadFolder())) {
      throw new Exception(
          "Download folder is not a directory:"
              + "\""
              + launchedBrowserOnRc.getBrowserDownloadFolder()
              + "\"");
    }

    String[] flList = rcFS.listFiles(launchedBrowserOnRc.getBrowserDownloadFolder());
    //			File[] flList= downLoadFolder.listFiles();
    if (flList == null || flList.length == 0) {
      return;
    }

    for (String fn : flList) {
      Pattern pattern = Pattern.compile(filePattern);
      File file = new File(fn);
      Matcher matcher = pattern.matcher(file.getName());
      if (matcher.matches()) {
        final String ffn = fn;
        new Wait() {
          public boolean until() {

            try {
              if (rcFS.isFileExist(ffn)) {
                if (!rcFS.delete(ffn)) {
                  throw new Exception("Error during file delition. File name=" + ffn);
                }
              }
              return true;
            } catch (Exception e) {
              return true; //
            }
          }
        }.wait("Error during file delition. File name=" + ffn, 30000, 1000);

        //					 if (rcFS.isFileExist(fn)) {
        ////						 if (!fl.delete()) {
        //						 if (!rcFS.delete(fn)) {
        //							 throw new Exception("Error during file delition. File name="+fn);
        //						 }
        //					 }

      }
    }
  }