rmdir question

Hi All,

 From the manual page of rmdir:
https://docs.perl6.org/routine/rmdir

       sub    rmdir(*@dirs --> List:D)
       method rmdir(IO::Path:D: --> True)

Does *@dirs mean I can give it multiple directories
as an array?

What does  "--> List:D" give me back?  An array
of Booleans as to which directories successfully removed?
And what is a "List:D?" anyway?


      ...throws an exception of type X::IO::Rmdir if
      the directory cannot be removed

Does this crash the program or just return a "false"?
Does it tell me what went wrong, as in "so and so" has
"such and such" file(s) open and locked?

To delete non-empty directory, see rmtree in File::Directory::Tree module.

Seems to me I should not have to import a module for
this.  Most rmdir command have a "parents" flag.  Am
I missing something?

Many thanks,
-T



-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A computer without Microsoft is like
a chocolate cake without the mustard
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
12/3/2019 2:37:10 AM
perl.perl6.users 1262 articles. 0 followers. Follow

3 Replies
4 Views

Similar Articles

[PageSpeed] 40

--000000000000b544560598c48c09
Content-Type: text/plain; charset="UTF-8"

It seems to me all your questions are answered by the very documentation
you referenced.

>> Does *@dirs mean I can give it multiple directories as an array?

Remove the invocant ....  in sub form .... of the provided directories in
the given list .....

Example:
-------------------------
# mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b')" ; ls -ld a b
drwxr-xr-x  2 root  wheel  2 Dec  2 22:22 a
drwxr-xr-x  2 root  wheel  2 Dec  2 22:22 b
ls: a: No such file or directory
ls: b: No such file or directory


>> What does  "--> List:D" give me back?

It gives you back a list of directories that it successfully removed.
Example:
--------------------------------
# mkdir a ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"
ls: b: No such file or directory
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 a
["a"]
# mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 a
drwxr-xr-x  2 root  wheel  2 Dec  2 22:23 b
["a", "b"]

>> And what is a "List:D?" anyway?

https://docs.perl6.org/type/Signature#Constraining_argument_definiteness

The above link explains it fully.  Though it uses "Int:D" as an example it
still applies.

>>      ...throws an exception of type X::IO::Rmdir if
>>     the directory cannot be removed
>>
>> Does this crash the program or just return a "false"?

On success it return a Bool::True.
On failure it throws an exception.
It doesn't crash the program.
If you are interested in handling the exception, add logic to handle it.

Examples:
---------------------------
# mkdir a ; `which perl6` -e "'a'.IO.rmdir.perl.say"
Bool::True
# mkdir a ; `which perl6` -e "'b'.IO.rmdir.perl.say"
Failure.new(exception => X::IO::Rmdir.new(path => "/root/test/b", os-error
=> "Failed to rmdir: no such file or directory"), backtrace =>
Backtrace.new)
# mkdir a ; `which perl6` -e "try { 'b'.IO.rmdir.perl.say; CATCH { default
{ 'tsk tsk'.say }}}"
tsk tsk


>> Does it tell me what went wrong, as in "so and so" has "such and such"
file(s) open and locked?
See previous example.  It throws an exception with a detailed error message.

>> To delete non-empty directory, see rmtree in File::Directory::Tree
module.
>>
>> Seems to me I should not have to import a module for
>> this.  Most rmdir command have a "parents" flag.  Am
>> I missing something?

It's true that most binaries with the name rmdir have a p switch for
removing "empty directories" which I won't argue could be added to perl6
proper.
That documentation you are referencing though is concerning "non-empty
directories" and there no such flag for any rmdir binary I've seen.

~Paul

On Mon, Dec 2, 2019 at 9:39 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
>  From the manual page of rmdir:
> https://docs.perl6.org/routine/rmdir
>
>        sub    rmdir(*@dirs --> List:D)
>        method rmdir(IO::Path:D: --> True)
>
> Does *@dirs mean I can give it multiple directories
> as an array?
>
> What does  "--> List:D" give me back?  An array
> of Booleans as to which directories successfully removed?
> And what is a "List:D?" anyway?
>
>
>       ...throws an exception of type X::IO::Rmdir if
>       the directory cannot be removed
>
> Does this crash the program or just return a "false"?
> Does it tell me what went wrong, as in "so and so" has
> "such and such" file(s) open and locked?
>
> To delete non-empty directory, see rmtree in File::Directory::Tree module.
>
> Seems to me I should not have to import a module for
> this.  Most rmdir command have a "parents" flag.  Am
> I missing something?
>
> Many thanks,
> -T
>
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> A computer without Microsoft is like
> a chocolate cake without the mustard
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>


-- 
__________________

:(){ :|:& };:

--000000000000b544560598c48c09
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>It seems to me all your questions are answered by the=
 very documentation you referenced.<br><br>&gt;&gt; Does *@dirs mean I can =
give it multiple directories as an array?<br></div><div><br></div><div>
Remove the invocant ....=C2=A0 in sub form .... of the provided directories=
 in the given list .....<br></div><div><br></div><div>Example:</div><div>--=
-----------------------</div><div># mkdir {a,b} ; ls -ld a b ; `which perl6=
` -e &quot;rmdir(&#39;a&#39;,&#39;b&#39;)&quot; ; ls -ld a b<br>drwxr-xr-x =
=C2=A02 root =C2=A0wheel =C2=A02 Dec =C2=A02 22:22 a<br>drwxr-xr-x =C2=A02 =
root =C2=A0wheel =C2=A02 Dec =C2=A02 22:22 b<br>ls: a: No such file or dire=
ctory<br>ls: b: No such file or directory<br></div><div><br></div><div><br>=
</div><div>
&gt;&gt; What does=C2=A0 &quot;--&gt; List:D&quot; give me back? <br></div>=
<div><br></div><div>It gives you back a list of directories that it success=
fully removed.</div><div>Example:</div><div>-------------------------------=
-<br></div><div># mkdir a ; ls -ld a b ; `which perl6` -e &quot;rmdir(&#39;=
a&#39;,&#39;b&#39;).perl.say&quot;<br>ls: b: No such file or directory<br>d=
rwxr-xr-x =C2=A02 root =C2=A0wheel =C2=A02 Dec =C2=A02 22:23 a<br>[&quot;a&=
quot;]<br># mkdir {a,b} ; ls -ld a b ; `which perl6` -e &quot;rmdir(&#39;a&=
#39;,&#39;b&#39;).perl.say&quot;<br>drwxr-xr-x =C2=A02 root =C2=A0wheel =C2=
=A02 Dec =C2=A02 22:23 a<br>drwxr-xr-x =C2=A02 root =C2=A0wheel =C2=A02 Dec=
 =C2=A02 22:23 b<br>[&quot;a&quot;, &quot;b&quot;]<br></div><div><br></div>=
<div>&gt;&gt; And what is a &quot;List:D?&quot; anyway? <br></div><div><br>=
</div><div><a href=3D"https://docs.perl6.org/type/Signature#Constraining_ar=
gument_definiteness">https://docs.perl6.org/type/Signature#Constraining_arg=
ument_definiteness</a></div><div><br></div><div>The above link explains it =
fully.=C2=A0 Though it uses &quot;Int:D&quot; as an example it still applie=
s.<br></div><div><br></div><div>&gt;&gt;=C2=A0 =C2=A0 =C2=A0 ...throws an e=
xception of type X::IO::Rmdir if<br>&gt;&gt; =C2=A0 =C2=A0 the directory ca=
nnot be removed<br>
&gt;&gt;<br>
&gt;&gt; Does this crash the program or just return a &quot;false&quot;?<br=
><br></div><div>On success it return a Bool::True.</div><div>On failure it =
throws an exception.</div><div>It doesn&#39;t crash the program.</div><div>=
If you are interested in handling the exception, add logic to handle it.<br=
></div><div><br></div><div>Examples:</div><div>---------------------------<=
/div><div># mkdir a ; `which perl6` -e &quot;&#39;a&#39;.IO.rmdir.perl.say&=
quot;<br>Bool::True</div><div># mkdir a ; `which perl6` -e &quot;&#39;b&#39=
;.IO.rmdir.perl.say&quot;<br>Failure.new(exception =3D&gt; X::IO::Rmdir.new=
(path =3D&gt; &quot;/root/test/b&quot;, os-error =3D&gt; &quot;Failed to rm=
dir: no such file or directory&quot;), backtrace =3D&gt; Backtrace.new)</di=
v><div># mkdir a ; `which perl6` -e &quot;try { &#39;b&#39;.IO.rmdir.perl.s=
ay; CATCH { default { &#39;tsk tsk&#39;.say }}}&quot;<br>tsk tsk</div><div>=
<br></div><div><br></div><div>&gt;&gt;=20
Does it tell me what went wrong, as in &quot;so and so&quot; has &quot;such=
 and such&quot; file(s) open and locked?=C2=A0</div><div>See previous examp=
le.=C2=A0 It throws an exception with a detailed error message.</div><div><=
br></div><div>&gt;&gt; To delete non-empty directory, see rmtree in File::D=
irectory::Tree module.<br>
&gt;&gt;<br>
&gt;&gt; Seems to me I should not have to import a module for<br>
&gt;&gt; this.=C2=A0 Most rmdir command have a &quot;parents&quot; flag.=C2=
=A0 Am<br>
&gt;&gt; I missing something?

<br><br></div><div>It&#39;s true that most binaries with the name rmdir hav=
e a p switch for removing &quot;empty directories&quot; which I won&#39;t a=
rgue could be added to perl6 proper.</div><div>That documentation you are r=
eferencing though is concerning &quot;non-empty directories&quot; and there=
 no such flag for any rmdir binary I&#39;ve seen.</div><div><br></div><div>=
~Paul<br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=
=3D"gmail_attr">On Mon, Dec 2, 2019 at 9:39 PM ToddAndMargo via perl6-users=
 &lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi All,<br=
>
<br>
=C2=A0From the manual page of rmdir:<br>
<a href=3D"https://docs.perl6.org/routine/rmdir" rel=3D"noreferrer" target=
=3D"_blank">https://docs.perl6.org/routine/rmdir</a><br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0sub=C2=A0 =C2=A0 rmdir(*@dirs --&gt; List:D)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0method rmdir(IO::Path:D: --&gt; True)<br>
<br>
Does *@dirs mean I can give it multiple directories<br>
as an array?<br>
<br>
What does=C2=A0 &quot;--&gt; List:D&quot; give me back?=C2=A0 An array<br>
of Booleans as to which directories successfully removed?<br>
And what is a &quot;List:D?&quot; anyway?<br>
<br>
<br>
=C2=A0 =C2=A0 =C2=A0 ...throws an exception of type X::IO::Rmdir if<br>
=C2=A0 =C2=A0 =C2=A0 the directory cannot be removed<br>
<br>
Does this crash the program or just return a &quot;false&quot;?<br>
Does it tell me what went wrong, as in &quot;so and so&quot; has<br>
&quot;such and such&quot; file(s) open and locked?<br>
<br>
To delete non-empty directory, see rmtree in File::Directory::Tree module.<=
br>
<br>
Seems to me I should not have to import a module for<br>
this.=C2=A0 Most rmdir command have a &quot;parents&quot; flag.=C2=A0 Am<br=
>
I missing something?<br>
<br>
Many thanks,<br>
-T<br>
<br>
<br>
<br>
-- <br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
A computer without Microsoft is like<br>
a chocolate cake without the mustard<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">__________________<br><br>:(){ :|:&amp; };:</div>

--000000000000b544560598c48c09--
0
pprocacci
12/3/2019 3:46:54 AM
>> On Mon, Dec 2, 2019 at 9:39 PM ToddAndMargo via perl6-users=20
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>>=20
>>     Hi All,
>>=20
>>       From the manual page of rmdir:
>>     https://docs.perl6.org/routine/rmdir
>>=20
>>             sub    rmdir(*@dirs --> List:D)
>>             method rmdir(IO::Path:D: --> True)
>>=20
>>     Does *@dirs mean I can give it multiple directories
>>     as an array?
>>=20
>>     What does  "--> List:D" give me back?  An array
>>     of Booleans as to which directories successfully removed?
>>     And what is a "List:D?" anyway?
>>=20
>>=20
>>            ...throws an exception of type X::IO::Rmdir if
>>            the directory cannot be removed
>>=20
>>     Does this crash the program or just return a "false"?
>>     Does it tell me what went wrong, as in "so and so" has
>>     "such and such" file(s) open and locked?
>>=20
>>     To delete non-empty directory, see rmtree in File::Directory::Tree=

>>     module.
>>=20
>>     Seems to me I should not have to import a module for
>>     this.  Most rmdir command have a "parents" flag.  Am
>>     I missing something?
>>=20
>>     Many thanks,
>>     -T

On 2019-12-02 19:46, Paul Procacci wrote:
> It seems to me all your questions are answered by the very documentatio=
n=20
> you referenced.
>=20
>  >> Does *@dirs mean I can give it multiple directories as an array?
>=20
> Remove the invocant ....=C2=A0 in sub form .... of the provided directo=
ries=20
> in the given list .....
>=20
> Example:
> -------------------------
> # mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b')" ; ls -ld=
 a b
> drwxr-xr-x =C2=A02 root =C2=A0wheel =C2=A02 Dec =C2=A02 22:22 a
> drwxr-xr-x =C2=A02 root =C2=A0wheel =C2=A02 Dec =C2=A02 22:22 b
> ls: a: No such file or directory
> ls: b: No such file or directory
>=20
>=20
>  >> What does=C2=A0 "--> List:D" give me back?
>=20
> It gives you back a list of directories that it successfully removed.
> Example:
> --------------------------------
> # mkdir a ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"
> ls: b: No such file or directory
> drwxr-xr-x =C2=A02 root =C2=A0wheel =C2=A02 Dec =C2=A02 22:23 a
> ["a"]
> # mkdir {a,b} ; ls -ld a b ; `which perl6` -e "rmdir('a','b').perl.say"=

> drwxr-xr-x =C2=A02 root =C2=A0wheel =C2=A02 Dec =C2=A02 22:23 a
> drwxr-xr-x =C2=A02 root =C2=A0wheel =C2=A02 Dec =C2=A02 22:23 b
> ["a", "b"]
>=20
>  >> And what is a "List:D?" anyway?
>=20
> https://docs.perl6.org/type/Signature#Constraining_argument_definitenes=
s
>=20
> The above link explains it fully.=C2=A0 Though it uses "Int:D" as an ex=
ample=20
> it still applies.
>=20
>  >>=C2=A0 =C2=A0 =C2=A0 ...throws an exception of type X::IO::Rmdir if
>  >> =C2=A0 =C2=A0 the directory cannot be removed
>  >>
>  >> Does this crash the program or just return a "false"?
>=20
> On success it return a Bool::True.
> On failure it throws an exception.
> It doesn't crash the program.
> If you are interested in handling the exception, add logic to handle it=
=2E
>=20
> Examples:
> ---------------------------
> # mkdir a ; `which perl6` -e "'a'.IO.rmdir.perl.say"
> Bool::True
> # mkdir a ; `which perl6` -e "'b'.IO.rmdir.perl.say"
> Failure.new(exception =3D> X::IO::Rmdir.new(path =3D> "/root/test/b",=20
> os-error =3D> "Failed to rmdir: no such file or directory"), backtrace =
=3D>=20
> Backtrace.new)
> # mkdir a ; `which perl6` -e "try { 'b'.IO.rmdir.perl.say; CATCH {=20
> default { 'tsk tsk'.say }}}"
> tsk tsk
>=20
>=20
>  >> Does it tell me what went wrong, as in "so and so" has "such and=20
> such" file(s) open and locked?
> See previous example.=C2=A0 It throws an exception with a detailed erro=
r message.
>=20
>  >> To delete non-empty directory, see rmtree in File::Directory::Tree =

> module.
>  >>
>  >> Seems to me I should not have to import a module for
>  >> this.=C2=A0 Most rmdir command have a "parents" flag.=C2=A0 Am
>  >> I missing something?
>=20
> It's true that most binaries with the name rmdir have a p switch for=20
> removing "empty directories" which I won't argue could be added to perl=
6=20
> proper.
> That documentation you are referencing though is concerning "non-empty =

> directories" and there no such flag for any rmdir binary I've seen.
>=20
> ~Paul
>=20

Thank you!
0
perl6
12/3/2019 4:28:00 AM
On 03/12/2019 04:46, Paul Procacci wrote:
> On success it return a Bool::True.
> On failure it throws an exception.
> It doesn't crash the program.
> If you are interested in handling the exception, add logic to handle it=
..
>
> Examples:
> ---------------------------
> # mkdir a ; `which perl6` -e "'a'.IO.rmdir.perl.say"
> Bool::True
> # mkdir a ; `which perl6` -e "'b'.IO.rmdir.perl.say"
> Failure.new(exception =3D> X::IO::Rmdir.new(path =3D> "/root/test/b",
> os-error =3D> "Failed to rmdir: no such file or directory"), backtrace
> =3D> Backtrace.new)
> # mkdir a ; `which perl6` -e "try { 'b'.IO.rmdir.perl.say; CATCH {
> default { 'tsk tsk'.say }}}"
> tsk tsk


Hi Paul,

thanks to your email I found and fixed an oversight in the Raku docs:

it says it throws an exception, when actually it returns a Failure.

Thank you!
=C2=A0 - Timo
0
timo
12/3/2019 5:56:03 PM
Reply: