OnJava8-Examples/files/DirectoryDemo.java

39 lines
1.0 KiB
Java
Raw Normal View History

// files/DirectoryDemo.java
2015-11-14 16:18:05 -08:00
// <20>2016 MindView LLC: see Copyright.txt
2015-06-15 17:47:35 -07:00
// Sample use of Directory utilities.
import java.io.*;
import onjava.*;
2015-06-15 17:47:35 -07:00
public class DirectoryDemo {
public static void main(String[] args) {
// All directories:
PPrint.pprint(Directory.walk(".").dirs);
// All files beginning with 'T'
for(File file : Directory.local(".", "T.*"))
2015-11-03 12:00:44 -08:00
System.out.println(file);
System.out.println("----------------------");
2015-06-15 17:47:35 -07:00
// All Java files beginning with 'T':
for(File file : Directory.walk(".", "T.*\\.java"))
2015-11-03 12:00:44 -08:00
System.out.println(file);
System.out.println("======================");
2015-06-15 17:47:35 -07:00
// Class files containing "Z" or "z":
for(File file : Directory.walk(".",".*[Zz].*\\.class"))
2015-11-03 12:00:44 -08:00
System.out.println(file);
2015-06-15 17:47:35 -07:00
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
[.\xfiles]
.\TestEOF.class
.\TestEOF.java
.\TransferTo.class
.\TransferTo.java
----------------------
.\TestEOF.java
.\TransferTo.java
.\xfiles\ThawAlien.java
======================
.\FreezeAlien.class
.\GZIPcompress.class
.\ZipCompress.class
2015-09-07 11:44:36 -06:00
*/