Logo Search packages:      
Sourcecode: jmk version File versions  Download package

static String [] edu::neu::ccs::jmk::FileOperator::glob ( String  fileName  )  throws CommandFailedException [inline, static, package]

This method expands a localized file name that may contain wild cards to an array of file names without the wild cards. All file separators in the file name must preceed any wild card.

Exceptions:
CommandFailedException if wild card is misused

Definition at line 95 of file FileOperator.java.

Referenced by glob().

  {
    int wildCardIndex = fileName.indexOf(wildCard);
    if (wildCardIndex < 0)    // No wild card
      return new String[] { fileName };
    else {
      int separatorIndex = fileName.lastIndexOf(File.separatorChar);
      if (separatorIndex > wildCardIndex) {
      String msg = "Cannot expand " + fileName;
      throw new CommandFailedException(msg);
      }
      String pattern;
      String dirName;
      File dir;
      if (separatorIndex >= 0) {
      pattern = fileName.substring(separatorIndex + 1);
      dirName = fileName.substring(0, separatorIndex + 1);
      dir = new File(dirName);
      }
      else {
      pattern = fileName;
      dirName = "";
      dir = new File(System.getProperty("user.dir"));
      }
      String[] list = dir.list(new WildCardFilter(pattern, wildCard));
      if (list == null)
      return new String[0];
      Vector v = new Vector();
      for (int i = 0; i < list.length; i++)
      list[i] = dirName + list[i];
      return list;
    }
  }


Generated by  Doxygen 1.6.0   Back to index