CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
archive directory with selected files

 



AlexPerl
Novice

Apr 14, 2014, 10:58 AM

Post #1 of 4 (2419 views)
archive directory with selected files Can't Post

How do I archive a directory in Perl, but select only the files to be archived?

This is the directory structure that I start with (directories and files):
/tmp/wip0
---dir1
------txt1a
------txt1b
------junk1a
---dir2
------txt2a
------txt2b
------junk2a
---dir3
------txt3a
------txt3b
------chref.log

I am hoping to get an archive wip0.tgz with this contents:
/wip0
---dir1
------txt1a
------txt1b
---dir2
------txt2a
------txt2b
---dir3
------txt3a
------txt3b


Laurent_R
Veteran / Moderator

Apr 14, 2014, 1:46 PM

Post #2 of 4 (2415 views)
Re: [AlexPerl] archive directory with selected files [In reply to] Can't Post

This is a relatively good example, but it lacks clear business or functional rules: how do I decide what to keep and what to forget about?


AlexPerl
Novice

Apr 14, 2014, 4:27 PM

Post #3 of 4 (2410 views)
Re: [Laurent_R] archive directory with selected files [In reply to] Can't Post

can we do a tar -selectfilenames *txt > wip0.tgz?

or, select from the list:

list = "./dir*/txt*";
print "copy these files only $list";
tar -cf $list > wip0.tgz;

I'm doing this at work. And we normally archive only needed documents in a directory. The rest of the files are junks and we do not want to archive them. I'm writing Perl just for my own usage and our Linux support is limited.


Laurent_R
Veteran / Moderator

Apr 15, 2014, 1:10 AM

Post #4 of 4 (2406 views)
Re: [AlexPerl] archive directory with selected files [In reply to] Can't Post

I think that you probably want to take a look at the File::Find module: http://search.cpan.org/~rjbs/perl-5.18.2/lib/File/Find.pm.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives