in reply to Move or rename script

Okay, that should work exactly like /bin/mv, but that's because it is /bin/mv with a wrapper.

If you're looking into doing the move in Perl look at File::copy, which has a rather nice move method which does exactly what you seem to want to do, at least in skeleton- if you need the same command line options you can add them.

If you're after exactly the same functionality then look at Perl Power Tools, where people have tried to rebuild an mv in Perl with full functionality.

Update: Wrote File::find rather than File::copy in first version. Oops.

Replies are listed 'Best First'.
Re: Re: Move or rename script
by Anonymous Monk on May 24, 2002 at 15:07 UTC
    Actually I would like to try and do it within a perl script without using modules similiar to how I did my create directory:
    #!/usr/local/bin/perl sub mak { !system "/bin/mkdir", @_; } print "Enter name of Directory you want to create: "; chomp($newb = <STDIN>); mak $newb; print "$newb directory created.\n";
    Can the same be done with the move command except I want to use command line arguments when the script is invoked???

      You say you want to "move or rename" something.

      Let's see

       # perldoc -f move
       No documentation for perl function `move' found
      
      
      ok, so let's try the other
      
       # perldoc -f rename
          rename OLDNAME,NEWNAME
                  Changes the name of a file; an existing file NEWNAME will be
                  clobbered. Returns true for success, false otherwise.
                  ...
      

        Jenda

      use backticks `` to make your system calls. (sorry I cant find a good link)

      any arguments can just be passed into the backtick.

      i.e. a recursive list of files that could be split with "\n" into an array.<br /
      @foo = `find $path -name $ftype`;

      And for move:

      $where = '/home/iordy/public_html/';
      $what = '/home/iordy/whatever.pl';
      @foo = `mv $args $what $where`;