예제 #1
0
  /**
   * lookupEntryIn: pathName index: index "Look up the index-th entry of the directory with the
   * given path (starting from the root of the file hierarchy) and return an array containing:
   *
   * <p><name> <creationTime> <modificationTime> <dirFlag> <fileSize>
   *
   * <p>The creation and modification times are in seconds since the start of the Smalltalk time
   * epoch. DirFlag is true if the entry is a directory. FileSize the file size in bytes or zero for
   * directories. The primitive returns nil when index is past the end of the directory. It fails if
   * the given pathName is bad."
   *
   * <p><primitive: 162> self primitiveFailed.!
   */
  Object lookupEntryInIndex(int argCount) {
    if (argCount != 2) throw fHandler.primitiveFailed();

    SqueakObject fullPath = fHandler.stackNonInteger(1);
    int index = fHandler.stackInteger(0) - 1;

    if (index < 0) throw fHandler.primitiveFailed();

    String filename = fullPath.asString();
    if (filename.trim().length() == 0) filename = "/";

    File directory = new File(fullPath.asString());
    if (!directory.exists()) throw fHandler.primitiveFailed();

    File[] paths = directory.listFiles();
    if (index < paths.length) return makeDirectoryEntryArray(paths[index]);

    return fHandler.squeakNil();
  }