Mass file renaming AND creating...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Mass file renaming AND creating...

Post by jclarkkent2003 »

Hello All,
I am in very much need of help that would save me like 2 days of manual work. I am running windows xp home edition sp2 on my personal computer where the files are, and if I could do this on my own pc that would be awesome, if I MUST upload to my linux server where it has apache and php, I can. I would rather use a program to do this, or if I have to do in php, just let me know how and I will install it on my home pc.

Thanks in advance for all help~! I am very tired and not having a good month this month.

This is two parts:

Part 1:

I have say 3000 .php files, and right now they are named things like

php_file_1.php

and I need to rename them to

information-content-1.php.


They are like 200 files named this, and then there are 2800 files named ALL different files, and all I need to is change the separators from "_" to "-".

I don't want to use mod rewrite on the server to do this, I HAVE to rename all the files with preferably with - instead of _ , is there an easy way to do this?




PART 2:
NEXT, I need to CREATE files from a template, say I have a file named TEMPLATE.PHP, and I have a folder of 2000 flash files, I want to CREATE 2000 .PHP files, named the EXACT name of the .swf files, and the content in the .php files should be Identical to the TEMPLATE.PHP. So basically I want to copy and rename TEMPLATE.php 2000 times, easily.

If I could setup filters to edit things inside the newly created files, like say It has a field named $name = " the file name 1", or increase the $count var in each php file that I create, that would be tight~!

I appreciate any and all help please~
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Mass file renaming AND creating...

Post by timvw »

jclarkkent2003 wrote: some basic file manipulations
Offcourse you can write your own little php script that iterates over all the files in a directory, and with a preg_match discover what the number after _ is.
Once you have done this, the renaming should be a breeze :)

=> lookup http://www.php.net/glob, http://www.php.net/preg_match and http://www.php.net/rename

The second problem is similar, because instead of renaming, you should touch/create the file.

=> lookup http://www.php.net/fopen ('w' option)

Or if you prefer Visual Basic Scripting here's a little snipped i wrote a while ago http://timvw.madoka.be/programming/vbs/fsotest.vbs.txt (I know, it's dirty, but it did the job :)
jclarkkent2003
Forum Contributor
Posts: 123
Joined: Sat Dec 04, 2004 9:14 pm

Post by jclarkkent2003 »

thanks,.

I have never used visual basic, I have two years expirence of an outdated language c++, and I know php quite well. I am up for learning visual basic, I am downloading ms vb 6.0++ professional edition, but I think i'm going to use php for this since I know it quite well.

I need to install php on my windows xp home edition sp2 pc, and make CERTAIN it's only accessable locally, I have had experience in the past getting rooted through php and all my files deleted, is it easy to secure php on my pc at home? What should I do to make sure it's secure, first off, I'm not running apache on this computer, so would php even be accessable off my pc?

Anyone got a link where I can find a tutorial on installing php on windows XP home edition sp2 ?

Cheers~
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

we even have a WAMP tutorial set up to help with this.

viewtopic.php?t=24149
Post Reply