Go Back   Trackpads Community > General Discussions > Computer and Technology > Web Design

Web Design Forums and discussions on webdesign

Web Design

Reply
 
LinkBack Thread Tools
Old 08-28-2005, 00:00   #1 (permalink)
Toby Inkster
Civilians

 
Default Useful script perhaps

Perl script below runs a particular command on multiple files.

I use this script when I've written a bunch of PHP pages that I need to
upload to a server with no PHP support. I create the PHP pages using
".html" extensions and then run:

folder.pl 'php {} >../{}' *.html

Here is the script:

==================== folder.pl ====================
#!/usr/bin/perl

use Getopt::Long qw(GetOptions);
my $VERSION = '1.1';
my $opts;

GetOptions
(
"usage|help|h" => \$opts{'help'},
"version" => \$opts{'version'},
"verbose|v+" => \$opts{'verbose'}
);

if ($opts{'version'}==1)
{
print "$VERSION\n";
}

&errormessage if ($opts{'help'}==1);

$cmd = shift @ARGV || &errormessage;
$nfiles = 0;

while ($_ = shift @ARGV)
{
$nfiles++;
$c = $cmd;
$c =~ s/\{\}/$_/g;
print '$ ' . $c . "\n"
if ($opts{'verbose'}==1);
system($c);
}


if ($nfiles==0)
{
die "Must specify some files!\n"
}
else
{
print "$nfiles files processed.\n"
if ($opts{'verbose'}==1);
}


sub errormessage
{
print "\n";
print "folder.pl - folds a command onto multiple files\n";
print "Version $VERSION (c) 2005 Toby Inkster\n";
print "License: http://www.gnu.org/copyleft/gpl.html\n\n";
print "USAGE: folder.pl [options] command file [file...]\n\n";
print " \"command\" is a command to run on each file. Use {} to refer to the\n";
print " filename (much like the \"find\" command). You may find it benificial\n";
print " to use \'single quotes\' around the command.\n\n";
print " Many UNIX shells provide similar built-in functionality, but folder.pl\n";
print " has an easier syntax.\n\n";
print "OPTIONS:\n";
print " --verbose -v Be verbose.\n";
print " --usage --help -h Display help message.\n";
print " --version Display version.\n\n";
print "EXAMPLES:\n";
print " folder.pl \'php {} >../{}.html\' *.php\n";
print " folder.pl \'mv {} {}l\' *.htm\n";
print "\n";
exit;
}
================================================== =

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Trackpads Information
Click to Visit
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
IE script Error =?Utf-8?B?QWNjZXNzTnViaWU=?= Microsoft Applications 2 12-01-2004 16:00
script.js Kurt Van Keymeulen Microsoft Applications 5 08-02-2004 10:30
Which Script Are They Using? http://links.i6networks.com Web Design 2 08-02-2004 09:30
Need Help with PHP Script mcp6453 Web Design 2 07-08-2004 07:29
VB script Antony Microsoft Applications 1 06-16-2004 07:46


Community Information
Options
Quick Options
Trackpads Non-Commercial Ad
Copyright Information Click to Visit
Time
Server Time
All times are GMT -4. The time now is 21:31.
Copyright
Copyright Information
The header is based off of work by Vipixel.com and modified by this site. Trackpads and the Trackpads Logo are both Registered Trademarks of Jason Edwards and cannot be used without prior written permission.  The only exception is as a link back to this site. Trackpads is a private website run by a small legion of volunteers, 3 dogs, 12.5 cats and an army of small, super smart, bio-engineered mice with pointy hats and tutu's. Search Engine Friendly URLs by vBSEO 3.2.0 RC7
Archive Links
Archive Links
Page generated in 0.70430 seconds with 19 queries