Click to See Complete Forum and Search --> : changing .php3 to .php


Alicia
12-31-2003, 02:53 AM
Hi guys,

Currently i have more than 50 files are in php3 extension... is there anyway or tools i can use to change all the files' extension to php just by a click ??

i can use dreamweaver sitemap search and replace feature to change .php3 to .php in the source code, but i dun think it can be used to change the file extension..

any suggestion besides of changing the files extension manually one by one ??

please advise..

p.s: will the code not working once i changed the extension ?

hyperstyle
12-31-2003, 03:24 AM
by the time you get a response that you can use you would have competed the task if you did it manually. I do know there are are few programs out there that can do this, i just have no idea what they are called. Go do download.com or something and search for 'mass file rename'

Pittimann
12-31-2003, 05:09 AM
Hi!

If your OS permits you to open a DOS window, you can use the good old rename command with wildcards.

Open the DOS window, change to the folder with your .php3 files ('cd..' and pressing enter bringing you one directory instance up, cd directoryname => enter bringing you to the directory with the name 'directoryname'), then type:

ren *.php3 *.php

confirm by pressing enter and there you are.

Cheers - Pit

stoodder
01-01-2004, 02:58 PM
yea, im not sure if your worried about liek formatting the files, liek their codes are diffrent or whatever b ut im prettysure you should have to worry about that if you just rename it .php it shoudl work fine!

Cainofnod
01-01-2004, 11:39 PM
Perl does fun things like that really easy:


#!/usr/bin/perl -w
use strict;
my $dir = '.';
opendir DIR, $dir or die $!;
for (readdir DIR) {
my ($fn, $fe) = split /\./, $_;
rename $_, $fn . '.php' if /\.php3$/i;
}
close DIR;


That will work for you I think.

pyro
01-02-2004, 08:05 AM
So does PHP:

<?PHP
$dir = "/temp/extchanger/"; # absolute path to the directory files are located in, minus domain
$old_ext = ".php3"; # including the .
$new_ext = ".php"; # including the .

$handle = opendir($_SERVER['DOCUMENT_ROOT'].$dir);

while (false !== ($file = readdir($handle))) {
if (is_file($_SERVER['DOCUMENT_ROOT'].$dir.$file)) {
if (preg_match("/$old_ext$/", $file)) {
$base = basename($file,"$old_ext");
rename($file, $base.$new_ext);
}
}
}
?>