Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (61 sloc) 2.897 kb
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
1 /* __ *\
2 ** ________ ___ / / ___ Scala API **
2d11a5b Updated copyright notices to 2011
Antonio Cunei authored
3 ** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
4 ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5 ** /____/\___/_/ |_/____/_/ | | **
6 ** |/ **
7 \* */
8
9 package scala.tools.nsc
10 package io
11
10bcc73 @paulp Some minor compiler support bits for my upcomin...
paulp authored
12 object Directory {
df94b3c @paulp Some much needed housecleaning regarding system...
paulp authored
13 import scala.util.Properties.{ tmpDir, userHome, userDir }
bb149d1 @paulp A few compiler IO lib bits I have been needing:...
paulp authored
14
48e9663 @paulp Reverting the rest of it until I can look with ...
paulp authored
15 private def normalizePath(s: String) = Some(apply(Path(s).normalize))
df94b3c @paulp Some much needed housecleaning regarding system...
paulp authored
16 def Current: Option[Directory] = if (userDir == "") None else normalizePath(userDir)
17 def Home: Option[Directory] = if (userHome == "") None else normalizePath(userHome)
bb149d1 @paulp A few compiler IO lib bits I have been needing:...
paulp authored
18 def TmpDir: Option[Directory] = if (tmpDir == "") None else normalizePath(tmpDir)
19
10bcc73 @paulp Some minor compiler support bits for my upcomin...
paulp authored
20 def apply(path: Path): Directory = path.toDirectory
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
21
22 // Like File.makeTemp but creates a directory instead
23 def makeTemp(prefix: String = Path.randomPrefix, suffix: String = null, dir: JFile = null): Directory = {
24 val path = File.makeTemp(prefix, suffix, dir)
25 path.delete()
26 path.createDirectory()
27 }
28 }
29 import Path._
30
31 /** An abstraction for directories.
32 *
33 * @author Paul Phillips
34 * @since 2.8
35 */
1b14f49 @paulp More support code for the big partest patch I'm...
paulp authored
36 class Directory(jfile: JFile) extends Path(jfile) {
2bf117c @paulp Some minor I/O changes. No review.
paulp authored
37 override def toAbsolute: Directory = if (isAbsolute) this else super.toAbsolute.toDirectory
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
38 override def toDirectory: Directory = this
39 override def toFile: File = new File(jfile)
40 override def isValid = jfile.isDirectory() || !jfile.exists()
ae71711 @paulp More partest cleanups, and putting back a coupl...
paulp authored
41 override def normalize: Directory = super.normalize.toDirectory
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
42
43 /** An iterator over the contents of this directory.
44 */
45 def list: Iterator[Path] =
46 jfile.listFiles match {
47 case null => Iterator.empty
48 case xs => xs.iterator map Path.apply
49 }
50
a09cf5d @paulp Renamed partialMap to collect.
paulp authored
51 def dirs: Iterator[Directory] = list collect { case x: Directory => x }
52 def files: Iterator[File] = list collect { case x: File => x }
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
53
d5c7049 @paulp Mostly IO tweaks related to my upcoming partest...
paulp authored
54 override def walkFilter(cond: Path => Boolean): Iterator[Path] =
55 list filter cond flatMap (_ walkFilter cond)
56
d12ea6d @paulp Some IO conveniences. No review.
paulp authored
57 def deepDirs: Iterator[Directory] = Path.onlyDirs(deepList())
58 def deepFiles: Iterator[File] = Path.onlyFiles(deepList())
59
e31f180 @paulp Small adjustment to Directory.
paulp authored
60 /** If optional depth argument is not given, will recurse
61 * until it runs out of contents.
62 */
63 def deepList(depth: Int = -1): Iterator[Path] =
64 if (depth < 0) list ++ (dirs flatMap (_ deepList (depth)))
65 else if (depth == 0) Iterator.empty
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
66 else list ++ (dirs flatMap (_ deepList (depth - 1)))
67
68 /** An iterator over the directories underneath this directory,
69 * to the (optionally) given depth.
70 */
71 def subdirs(depth: Int = 1): Iterator[Directory] =
a09cf5d @paulp Renamed partialMap to collect.
paulp authored
72 deepList(depth) collect { case x: Directory => x }
e604abb @paulp Resurrected the former contents of scala.io in ...
paulp authored
73 }
Something went wrong with that request. Please try again.