avik1612 has asked for the wisdom of the Perl Monks concerning the following question:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Copy folders
by Samy_rio (Vicar) on Aug 28, 2007 at 07:21 UTC | |
Hi avik1612, copy the folder using File::Copy::Recursive
Regards, eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j'; | [reply] [d/l] [select] |
Re: Copy folders
by andreas1234567 (Vicar) on Aug 28, 2007 at 07:14 UTC | |
-- Andreas | [reply] [d/l] [select] |
Re: Copy folders
by moritz (Cardinal) on Aug 28, 2007 at 06:59 UTC | |
Did the program compile? Did you get any error message? If the copy failed, did you print out $! for more information?
As andreas1234567 pointed out File::Copy is not suitable, but dircopy in File::Copy::Recursive does what you want | [reply] [d/l] [select] |
Re: Copy folders
by SM177Y (Initiate) on Sep 13, 2015 at 12:57 UTC | |
Here is a pure perl method I made up after endless searching and having people tell me to use modules. This is such a simple concept, a required external module seems pretty lame. I have also made a recursive directory deleter so I/You can eliminate the need for File::Path qw(remove_tree) and File::Copy::Recursive qw(rcopy) altogether. If you use these together you can easily conduct a dir_move. And finally I included an fmove(); (you could use rename for certain instances obviously and fmove is identical to fcopy except for a final unlink) but if you were to combine fmove() into dircopy you could make a single sub/function to move a folder in one shot instead of recursive copy and then recursive delete.
And here is the recursive directory deleter...
Just a side note: When using these make sure you run -d tests if you are not certain your target is a folder or a file. If it's just a file you can } else { unlink(file);}
| [reply] [d/l] [select] |
by afoken (Chancellor) on Sep 13, 2015 at 16:23 UTC | |
Sorry, this is junk. Here is why: Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] |
| |
by soonix (Chancellor) on Sep 14, 2015 at 10:36 UTC | |
… having people tell me to use modules. … a required external module seems pretty lame.I think these words were what itched afoken (and possibly other monks, too). A great deal of Perl's power comes from its already available modules. The "extern"-ness of File::Copy and File::Path is such that it is just a use statement away - no installation needed. Nothing against writing this anew from scratch -- as a learning experience, to explore new ways, or for special needs. But the possibility to use modules (and to create them, for your own custom logic that you need in multiple places) is one of Perl's strengths. | [reply] |
by SM177Y (Initiate) on Sep 14, 2015 at 23:00 UTC | |
| [reply] |
by karlgoethebier (Abbot) on Sep 16, 2015 at 13:29 UTC | |
|