@@ -12,6 +12,8 @@ windows), a directory, and a basename.
12
12
C < IO::Path > supports both purely textual operations, and operations that
13
13
access the file system.
14
14
15
+ The current working directory is available as an IO::Path object in C < $*CWD > .
16
+
15
17
The behavior of C < IO::Path > is dependent on the operating system it runs on;
16
18
to get reproducible behavior across operating systems, you can use one of its
17
19
subclasses instead: L < IO::Path::Unix > , L < IO::Path::Win32 > ,
@@ -20,10 +22,11 @@ L<IO::Path::Cygwin>, L<IO::Path::QNX>.
20
22
The rest of this document silently assumes Unix semantics in its examples,
21
23
unless when stated otherwise.
22
24
25
+
23
26
= for TODO
24
27
25
28
document the following methods: is-absolute, is-relative, absolute,
26
- relative, parent, child, copy, chmod, contents
29
+ relative, parent, child, copy,
27
30
28
31
= end for
29
32
@@ -102,4 +105,36 @@ as the L<open> function accepts.
102
105
Watches the path for modifications. Only implemented in Rakudo with the MoarVM
103
106
backend at the moment.
104
107
108
+ = head2 method contents
109
+
110
+ method contents (IO ::Path: D : Mu : $ test = none (' .' , ' ..' ))
111
+
112
+ Tries to interpret the path as a directory, and returns a lazy list of
113
+ C<IO::Path > objects that match the C<$test > smart-matcher.
114
+
115
+ By default , the C<. > and C<.. > entries (current directory, and parent
116
+ directory) are filtered out. To get a list of all files and directories,
117
+ simply pass a smart-matcher that always matches, like C<True >:
118
+ C<$path.contents(:test(True)) >, or shorter: C<$path.contents(:test) >.
119
+
120
+ An example that lists all files and directories recursively:
121
+
122
+ sub MAIN ($ dir = ' .' ) {
123
+ my @ todo = $ dir . path ;
124
+ while @ todo {
125
+ for @ todo . pop . contents -> $ path {
126
+ say $ path . Str ;
127
+ @ todo . push : $ path if $ path . d ;
128
+ }
129
+ }
130
+ }
131
+
132
+ = head2 method chmod
133
+
134
+ method chmod (IO ::Path: D : Int : D $ mode )
135
+
136
+ Changes the POSIX permissions of a file to C<$mode >.
137
+
138
+ $ * CWD . chmod (0o700 );
139
+
105
140
= end POD
0 commit comments