Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Attaching folders and sub-folders
Paul
Is there a way and if so, what is the best/correct way to be able to add a directory so that all files in that directory including sub folders and the files therein get attached to the workflow and ultimately deployed.
Parent folder > file, file,file, Sub-Folder > file, file, Sub-Folder file, file, file, file
Find more posts tagged with
Comments
Adam Stoller
The best way is to write code that traverses the directory to create a list of files to add and then use $task->AddMultipleFiles() - though if you're concerned about running into any locking issues or redundant adding issues - you probably need to loop through each file and do an individual $task->AddFile() so that you can check the return code / status and take the appropriate action in the case of an error.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Paul
Thank You.
Is there an example of this sort of thing? The only reference to AddFile() that I find in the documentation is on page 172 of the Workflow Developer's Guide
and I found areference to iwaddtaskfile in the CLT manual.
When I try to attach a directory to the workflow all I see is the directory name.
PageTypeNumbering55.ssd.zip
25128.pdf
Adam Stoller
perldoc TeamSite::WFtask
Attaching a directory may or may not do what you want (I'm not sure it works at all, but I can't say I've tried it recently) Writing your own code to parse directories and come up with a list of files is not that difficult if you've done a moderate amount of Perl coding and/or have access to various Perl books (O'Reilly recommended) - and frankly I think it's worth taking the time to write it yourself rather than getting spoon-fed someone else's code which you may or may not understand but for which you (or someone you hand off to) will become responsible for maintaining.
Things to look for: opendir(), readdir(), hashes, arrays, regex's, loops (for,foreach, while, etc.)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Migrateduser
For what it's worth, and I'm opening myself up to ridicule on this one, here's one way to do it. I use this and it works, which is all that matters to me. Performance is not a factor here. Once again, the standard disclaimer on me not being able to indent (even though fish has explained it to me at least 2 times):
=head1 get_recursive_files($basepath)
Returns an array of all files in the $basepath directory, in the passed in
deployment filelist format, and recurses down the list of subdirectories as well.
Example:
@files
= TeamSite::NikeUtils::get_recursive_files($basepath);
=cut
sub get_recursive_files {
my ($basepath) =
@_
;
my
@files
= ();
my
@basefiles
= ();
my $prefix = $basepath;
if ($prefix =~ /^.*WORKAREA\/[^\/]*\/(.*)$/) {
$prefix =~ s/^.*WORKAREA\/[^\/]*\/(.*)$/$1\//;
}
else {
$prefix = '';
}
return
@files
if (!-d $basepath);
opendir BASE,$basepath;
@basefiles
= readdir BASE;
closedir BASE;
# Recursively retrieve all files
foreach my $file (
@basefiles)
{
my $fullfile = "$basepath/$file";
if ((-d "$basepath/$file") && ($file !~ /^\.+$/)) {
push
@files
, get_recursive_files("$basepath/$file");
}
else {
push (
@files
, "$prefix$file") if ($file !~ /^\.+$/);
}
}
return
@files
;
}
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
Adam Stoller
As a courtesy service only - the indented version of Smitty's code (minor tweak in regex coding for readability).
Yes - I'd probably code it differently, but I don't feel like doing that right now ;-)
=head1 get_recursive_files($basepath)
Returns an array of all files in the $basepath directory, in the passed
in deployment filelist format, and recurses down the list of subdirectories
as well.
Example:
@files
= TeamSite::NikeUtils::get_recursive_files($basepath);
=cut
sub get_recursive_files {
my ($basepath) =
@_
;
my
@files
= ();
my
@basefiles
= ();
my $prefix = $basepath;
if ($prefix =~ m|^.*WORKAREA/[^/]*/(.*)$|) {
$prefix =~ s|^.*WORKAREA/[^/]*/(.*)$|$1/|;
}
else {
$prefix = '';
}
return
@files
if (!-d $basepath);
opendir BASE,$basepath;
@basefiles
= readdir BASE;
closedir BASE;
# Recursively retrieve all files
foreach my $file (
@basefiles)
{
my $fullfile = "$basepath/$file";
if ((-d "$basepath/$file") && ($file !~ /^\.+$/)) {
push
@files
, get_recursive_files("$basepath/$file");
}
else {
push (
@files
, "$prefix$file") if ($file !~ /^\.+$/);
}
}
return
@files
;
}
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com