Microsoft SDK for Java

FileEnumerator Class

Searches the file system for files that match a specified pattern.

package com.ms.wfc.io

public class FileEnumerator

Remarks

The following example shows how to use the FileEnumerator class to find and output the names of all Java files in and below a specified directory.

static void printJavaFiles(String path) {
    FileEnumerator e = new FileEnumerator(File.combine(path, "*.*"));
    while (e.hasMoreFiles()) {
        String name = e.getName();
        if ((e.getAttributes() & File.DIRECTORY) != 0) {
            if (!name.equals(".") && !name.equals("..")) {
                printJavaFiles(File.combine(path, name));
            }
        }
        else {
            String ext = File.getExtension(name);
            if (ext != null && ext.equalsIgnoreCase(".java")) {
                System.out.println(File.combine(path, name));
            }
        }
        e.getNextFile();
    }
}

© 1999 Microsoft Corporation. All rights reserved. Terms of use.