How can I tar multiple directories and also append files with some pattern like '.txt' and exclude some directories and exclude some patterns like '.exe' all into a single tar file. The main point is the number of directories are unknown(dynamic), so I need to loop through I guess?
+7
A:
I'd use Archive::Tar and populate @filelist
with Class::Path (specifically Class::Path::Dir
's recurse
method)
David Dorward
2010-03-30 14:29:52
I cannot use Archive::Tar, because i am using system call to create a tar file(its the requirement)$tarExe = "$toolDir/bin/gnu_tar/${binPlatform}/tar.exe";system("${tarExe} -cvf $tarname $location");
superstar
2010-03-30 14:33:44
You have a requirement to do it the hard way? There is no good reason to do that on a real project. Is this homework?
David Dorward
2010-03-30 14:35:37
i need to use tar.exe from the winx64 folder to create the tar file.This is standard method I was suggested to do. Its a real project to create tar files.
superstar
2010-03-30 14:38:34
Using a Perl module is the standard way to do things in Perl, shelling out to other binaries is not.
David Dorward
2010-03-30 14:42:37
I understand. But I have to do it this way. thats my problem...
superstar
2010-03-30 14:49:50
If it was a suggestion, then you don't have to do it that way. Do it the right way instead.
David Dorward
2010-03-30 14:51:23
Is there some requirement that no additional software be installed? If not, just install the module.
Sorpigal
2010-03-30 16:01:23
Archive::Tar comes with Perl (since 5.009003, according to corelist).
draegtun
2010-03-30 18:13:58
how do i make a system call to exclude some folders while TARring directories. i need to tar my1 and my2 from RandomName and myPacket as basetar.tar and exclude my3 from myPacket.This is what i have and it doesnt work...any suggestion?. tar -cvf basetar.tar input\RandomName\my1 input\RandomName\my2 input\myPacket --exclude=input\myPacket\my3
superstar
2010-03-30 18:28:45
If you have requirements that you cannot install modules, perhaps you could state this in the question so that if people spend (waste?) time answering you question ......
justintime
2010-03-30 18:30:31
A:
If for some reason you cannot, or are not permitted to, install additional modules beyond the base system you could use File::Find instead of Class::Path.
It sounds like you already know how to call out to the system tar command so I'll leave it at that.
Sorpigal
2010-03-30 16:09:55
+1
A:
Assuming you have worked out what files you want using File::Find then something like
my @dir = qw/a b/ ;
system "tar -cvf mytar @dir" ;
might work. But you might find that the command line is too long.
In which case maybe write the list of files to a file and use the option
--files-from=NAME
(and please don't tell me you are not allowed to write to files)
justintime
2010-03-30 18:28:05
It will break if any of the file names include a character with special meaning for the shell. Provide arguments as the list after the PROGRAM argument.
David Dorward
2010-03-30 23:10:38
presumably you are referring to my first suggstion. The files in --file-from would be safe against that.
justintime
2010-03-31 02:29:25