How to move files in perl recursively

How can i move all files in a directory to the previous directory in Perl using system command ?

I tried the following method and it showed error

system('/bin/mv "test/*" , "./"');

bash: syntax error near unexpected token '/bin/mv "test/*" , "./"''

Please help.

1

1 Answer

Perl has native methods for this. From CPAN:

fmove()

Copies the file then removes the original. You can manage the path the original file is in according to $RemvBase.

dirmove()

Uses dircopy() to copy the directory then removes the original. You can manage the path the original directory is in according to $RemvBase.

rmove()

Like rcopy() but calls fmove() or dirmove() instead.

And 1 that uses globbing:

rmove_glob()

Like rcopy_glob() but calls rmove() instead of rcopy()

It mentions ...

rcopy_glob()

This function lets you specify a pattern suitable for perl's glob() as the first argument. Subsequently each path returned by perl's glob() gets rcopy()ied.

It returns and array whose items are array refs that contain the return value of each rcopy() call.

It forces behavior as if $File::Copy::Recursive::CPRFComp is true.


From the examples in the link:

rmove('foo/bar/baz', '/etc/');
# "baz" is removed from foo/bar after it is successfully copied to /etc/
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like