develooper Front page | perl.perl6.users | Postings from December 2019

Re: rmdir question

Thread Previous
From:
ToddAndMargo via perl6-users
Date:
December 3, 2019 04:28
Subject:
Re: rmdir question
Message ID:
a87b110d-aa2e-891f-b727-c3e4988e805b@zoho.com
>> On Mon, Dec 2, 2019 at 9:39 PM ToddAndMargo via perl6-users 
>> <perl6-users@perl.org <mailto: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

On 2019-12-02 19:46, Paul Procacci wrote:
> 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
> 

Thank you!

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About