Simple Machines Community Forum

General Community => Scripting Help => Topic started by: James Bone on September 02, 2004, 03:25:52 AM

Title: Help please!
Post by: James Bone on September 02, 2004, 03:25:52 AM
Hello all you coding peeps! I am looking for a program (PHP or PERL) to go into a specified directory and change files that are named like this:

_0325153723_001.tif

and change their filename to:

Syyyymmddhhnnss.tif
so in this example
S20040325153723.tif

and move it to another directory.

Can anyone help?

If you want an incentive theirs a Gmail invite on offer!
Title: Re: Help please!
Post by: Christian Land on September 02, 2004, 05:58:38 AM
Something like this?

<?php

$source = '/tmp/'; // Source-Path
$dest = '/tmp/test/'; // Destination-Path

$pattern = '/_(\d+?)_(\d+?).tif/i';

//

$oDir = dir($source);

echo '<font face="courier">';

while (false !== ($entry = $oDir->read()))
{
if (is_file($source.$entry))
{
if (preg_match($pattern,$entry,$matches))
{

$newname = 'S2004'.$matches[1].'.tif';
rename($source.$entry, $dest.$newname);
echo htmlspecialchars($source.$entry).' ---&gt; '.htmlspecialchars($dest.$newname).'<br />';
}
}
}

echo '</font>';

$oDir->close();

?>
Title: Re: Help please!
Post by: James Bone on September 02, 2004, 06:51:57 AM
Thats exactly it!! Thanks alot!

PM me your email and i will send you a GMAIL invite.

James