HighDots Forums  

Renaming files based on Titles name

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Renaming files based on Titles name in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
contender54
 
Posts: n/a

Default Renaming files based on Titles name - 08-03-2004 , 12:57 PM






I have a problem, I have over 30,000 files that have files names simular to
"recipe_000001.htm" and I want to change the name of the file to reflect the
Title name within the htm file. Is this posible? Are there tools out there that
can look at the text within the file like the <Title></Title> tag. These are
recipes with very short titles. So what I am saying incase I lost you is that I
have a file and it's name is recipe_000001.htm and I want to pull the Title
name from the file <title>Chicken Breast</title> and rename the file name to
chickenbreast.htm
Thanks, any help would be appreciated..
Rick


Reply With Quote
  #2  
Old   
Michael Fesser
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-03-2004 , 03:13 PM






.oO(contender54)

Quote:
I have a problem, I have over 30,000 files that have files names simular to
"recipe_000001.htm" and I want to change the name of the file to reflect the
Title name within the htm file. Is this posible? Are there tools out there that
can look at the text within the file like the <Title></Title> tag.
Don't know about existing tools, but it should be quite simple to write
a short script for doing this. Do you have PHP (for example) available
on the server?

Micha


Reply With Quote
  #3  
Old   
contender54
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-03-2004 , 04:14 PM



I do have php on my server and locally which is where I am making the changes.
I haven't pushed up the files yet.
The big problem is I only know PHP enough to get myself in trouble. But thanks
for the suggestion. Maybe I'll look around the php site's to see if anyone has
already created something similar. Or if you would like to help out that would
be great!.
Thanks
Rick


Reply With Quote
  #4  
Old   
Michael Fesser
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-04-2004 , 11:59 AM



.oO(contender54)

Quote:
I do have php on my server and locally which is where I am making the changes.
I haven't pushed up the files yet.
The big problem is I only know PHP enough to get myself in trouble. But thanks
for the suggestion. Maybe I'll look around the php site's to see if anyone has
already created something similar. Or if you would like to help out that would
be great!.
OK, I've played around a bit ... the script has become slightly more
complicated because of some error checking and statistics:

<http://www.mfesser.de/temp/rename/rename.php> (plain source code)
<http://www.mfesser.de/temp/rename/rename.phps> (highlighted syntax)

Store it somewhere on your disk where the webserver can reach it.

After that adjust the PATH constant which is defined at the beginning of
the script to point to the directory where your pages are stored. It has
to be the absolute path from the root of the filesystem (on Unix it's
usually something like "/var/www/...", on Windows for example
"c:\apache\htdocs\...").

Then call the script in your browser, e.g.

<http://localhost/rename.php>

It opens the given directory (and all subdirectories if existent) and
checks what files can be renamed. In this first step _no_ renaming is
done, the script only prints out how it _would_ rename the files if
possible. For 30.000 files this could take a while ... At the end it
dumps a simple statistic with the number of found files, errors etc.

If everything looks fine without too many "failed"-messages (ideally the
"loaded" and "skipped" numbers should be the same, while "renamed" and
"failed" should be zero), call the script a second time, this time with
an URL-parameter "rename", e.g.

<http://localhost/rename.php?rename>

It now renames the files.

It would be wise to make a backup of the files before performing this
second step. I've tested it on my system and it works, but of course
that's no guarantee that it works 100% on your system (there could arise
some problems with titles containing some special chars for example).
Additionally I've only tested it on my Linux box, I can't test it on
Windows (but it should also work there).

HTH
Micha


Reply With Quote
  #5  
Old   
contender54
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-04-2004 , 12:05 PM



Thanks I 'll give this a shot. I really do appreciate your help.
Rick

Reply With Quote
  #6  
Old   
contender54
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-04-2004 , 01:52 PM



Micha, I recieved a fatal error;
<b>Fatal error</b>: Maximum execution time of 300 seconds exceeded in:
I guess it's either the php config file has to be changed to a higher number,
what would you suggest?
Rick


Reply With Quote
  #7  
Old   
contender54
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-04-2004 , 02:43 PM



well I changed the timeout in the php.ini file, no-joy. So I guess I'll add the "set_time_limit(0) to the rename.php but where should I add it?
Thanks
Rick

Reply With Quote
  #8  
Old   
Michael Fesser
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-04-2004 , 03:14 PM



.oO(contender54)

Quote:
Micha, I recieved a fatal error;
b>Fatal error</b>: Maximum execution time of 300 seconds exceeded in:
Hmm, quite possible with 30.000 files to rename.

What machine does PHP run on? What frequency and how much memory? Was
there some output from the script? If yes, what was the highest number?

Quote:
I guess it's either the php config file has to be changed to a higher number,
what would you suggest?
Since it's on your local server I would simply increase the execution
time of scripts in the php.ini (max_execution_time). You could also
check out the set_time_limit() function.

<http://www.php.net/set_time_limit>

HTH
Micha


Reply With Quote
  #9  
Old   
Michael Fesser
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-04-2004 , 04:29 PM



.oO(contender54)

Quote:
well I changed the timeout in the php.ini file, no-joy.
Dependent on your system it might be necessary to restart the webserver.

Quote:
So I guess I'll add the "set_time_limit(0) to the rename.php but where
should I add it?
At the very beginning, after the opening <?php.

Micha


Reply With Quote
  #10  
Old   
contender54
 
Posts: n/a

Default Re: Renaming files based on Titles name - 08-05-2004 , 10:07 AM



Micha,
Tried to email you and I sent the errors and code. Anyway I am getting this
error now that I added the set_time_limit(0)
Parse error: parse error, unexpected T_STRING in
d:\nusphere\techplat\apache\htdocs\gourmetjuly\ren ame.php on line 4
This is the top part of the php

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
<?php
set_time_limit(0)

define('PATH', 'd:\NuSphere\TechPlat\apache\htdocs\gourmetjuly\re cipe_print');

run();

function run() {
global $counters;
$counters = array(
'loaded' => 0,
'renamed' => 0,
'skipped' => 0,
'failed' => 0
);
header('Content-Type: text/plain');
iterateDir(PATH);
print "\nresult: ";
print_r($counters);
}

--------------------------------------------------------------------------------
-------------------------------------------------------------------------
would you like me to email you a zipped up file that has a few of the files in
it so you can take a look?
Rick/Contender54


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.