develooper Front page | perl.perl6.users | Postings from June 2018

Re: need mkdir, chown, chmod, del

Thread Previous | Thread Next
From:
ToddAndMargo
Date:
June 4, 2018 04:50
Subject:
Re: need mkdir, chown, chmod, del
Message ID:
29a10fc7-4b23-3297-7a6d-be635dba05b8@zoho.com
On 06/03/2018 10:04 AM, ToddAndMargo wrote:
> Hi All,
> 
> I need the Perl6 commands for the following LINUX
> commands.
> 
> mkdir      make directory
> chown      change ownership
> chmod      change file mode bits
> del        delete file
> 
> 
> Many thanks,
> -T
> 
> 

Hi All,

Today's final Keeper file on IO

-T


Perl 6: File commands

Reference: https://docs.perl6.org/type/IO::Path

Note: copy and move are at the bottom of this list


chown (change ownership):
    Not implemented; use a system call


Directory, make:
     mkdir DIRPATH, attrible
        mkdir $WorkingDir, 0o766;
     Note: `mkdir` will create parent directories recursively


Directory, remove:
     rmdir PATH
     Delete all specified ordinary files, links, or symbolic links.
     returns True (1) or False (0)

         if rmdir $DirPath { say "worked } else { say "directory remove 
failed" };

     For recursive (parents), use `rmtree` in the 
`File::Directory::Tree` module, or
     use a sysem call to `rmdir --parents DIR`
         $RtStr, $RtnErr, $RtnCode = RunNoShellErr( "rmdir --Parents 
{$DirPath}" );



Delete:
     unlink PATH
     Delete all specified ordinary files, links, or symbolic links.
     returns True (1) or False (0)

         if unlink $FileName { say "worked } else { say "Delete Failed" };


Directory (ls, dir):
     dir PATH
        for dir "{$WorkingDirectory}" -> $Content { say $Content };

     Note: for a recursice rmdir, use
        https://github.com/labster/p6-file-directory-tree


Exists (directory):
    DIRPATH.IO.d.Boo;
        if not $WorkingDir.IO.d.Bool { mkdir $WorkingDir, 0o766; }


Exists (file):
    FILEPATH.IO.e
        if  $NewFileName.IO.e { $NewFileSize = $NewFileName.IO.s; } else 
{ return 4; }


File permission (retrieve):
     say "path/to/file".IO.mode;


File permission (set):
     PERMISSIONS."path/to/file".IO.mode;
          0o755.$FilePath.IO.mode;
              chmod 0o755, < myfile1 myfile2 >;   <-- DON'T FORGET THE 
COMMA!
              $ p6 'chmod 0o777, < "a", "b", "c" >;'
              $ p6 'chmod 0o777, < a b c >;'
              $ p6 'chmod 0o777, "a", "b", "c";'
              $ p6 'my $x = "a"; chmod 0o777, < $x b c >;'


Size:
    FILEPATH.IO.s
        $FileSize = $CorePath.IO.s;



catdir  (Concatenates multiple path fragments)
https://docs.perl6.org/routine/catdir

chdir
https://docs.perl6.org/routine/chdir

curdir  (current directory)
https://docs.perl6.org/routine/curdir

curupdir (Returns a none Junction of strings representing the current 
directory
           and the "one directory up")
https://docs.perl6.org/routine/curupdir

dir
https://docs.perl6.org/routine/dir

      $ perl6 -e 'for dir() -> $x { my $y="$x"; say $y };'
      $ perl6 -e 'for dir("/home/kvm") -> $x { my $y="$x"; say $y };'

      Note in the above, $x is an IO::Path, not a string.  Assigning
      it to $y converts it.  The Quotes around "$x" are necessary

dir-sep (Returns the string "/" "\" representing canonical directory 
separator character)
https://docs.perl6.org/routine/dir-sep

dirname
https://docs.perl6.org/routine/dirname

indir
https://docs.perl6.org/routine/indir
      "indir" is not "is this file in this directory?", it's "run this 
code in this
      directory instead of where I am now". So it's complaining that you 
didn't tell
      it what code to run there.

mkdir
https://docs.perl6.org/routine/mkdir

rmdir
https://docs.perl6.org/routine/rmdir

rootdir (Returns string '/', representing root directory)
https://docs.perl6.org/routine/rootdir

splitdir (Splits the given $path on slashes and backslashes)
https://docs.perl6.org/routine/splitdir

tmpdir
https://docs.perl6.org/routine/tmpdir

updir
https://docs.perl6.org/routine/updir

move
https://docs.perl6.org/routine/move

copy
https://docs.perl6.org/routine/copy

Thread Previous | Thread Next


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