Re: converting .php files to .dhtml

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Maw, 2005-07-19 at 18:16 +0530, Ankush Grover wrote:
> I wanted to test this out but out application is big and there are
> lots of subdirectories and many php files (500 files).So it is
> difficult to change the extension of every php file manually.

Its actually one of the harder problems in shell script to do this

The tools you need are "basename" "find" and "mv"

Basename will trim the ending off a name

eg

%basename fred.php .php
fred

mv you hopefully know

and find generates a list of files matching some rules and optionally
applies an action to them. So we can do

find . -name "*.php" -print

and get a list of the PHP files

So

for i in $(find . -name "*.php" -print)
do
	echo $i
done

will also print all the names using shell script

Next we can do

for i in $(find . -name "*.php" -print)
do
	echo $(basename $i .php)
done

and we should see all the names without php

and finally (after making a backup!)

for i in $(find . -name "*.php" -print)
do
	mv $i $(basename $i .php)".dhtml"
done



You might need more quotes if you use filenames containing spaces or *
but I've left that out to avoid confusion in the explanation


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux