|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.examples.scripts; import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.Repository; import org.openide.windows.InputOutput; import org.openide.windows.IOProvider; public class ListFiles { public static void main (String[] args) throws Exception { String pattern; if (args.length == 1) pattern = args[0]; else throw new Exception ("Arguments: one substring to match"); InputOutput io = IOProvider.getDefault ().getIO ("Matches for " + pattern, true); io.select (); PrintWriter pw = io.getOut (); pw.println ("Scanning for `" + pattern + "'..."); Enumeration fss = Repository.getDefault ().getFileSystems (); while (fss.hasMoreElements ()) { FileSystem fs = (FileSystem) fss.nextElement (); if (! fs.isHidden ()) { FileObject fo = fs.getRoot (); scan (fo, pattern, pw); } } pw.println ("Done."); } private static void scan (FileObject fo, String pattern, PrintWriter pw) throws IOException { if ((fo.getName () + '.' + fo.getExt ()).indexOf (pattern) != -1) pw.println (fo.getPath()); if (fo.isFolder ()) { FileObject[] children = fo.getChildren (); for (int i = 0; i < children.length; i++) scan (children[i], pattern, pw); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.