Multi-file replace Query

K

KiwiBrian

I have a need to replace every occurance of a particular graphic file which
occurs in many folders, at several levels, in a site that I have on my hard
drive.
I can tolerate the new file having a different name if this is necessary for
the process as I can do a site-wide rename of every ocurance of that
filename within the source files, but I don't know of any tool or
application that will let me replace the actual files.
Any help or pointers appreciated
Brian Tozer
 
D

David Dorward

KiwiBrian said:
I have a need to replace every occurance of a particular graphic file
which occurs in many folders, at several levels, in a site that I have on
my hard drive.

On one line:

find /path/to/site/root -name name_of_file.png -exec
cp /path/to/new/version.png {} \;
 
N

NOXwebmasterx

KiwiBrian said:
I have a need to replace every occurance of a particular graphic file
which occurs in many folders, at several levels, in a site that I have on
my hard drive.
I can tolerate the new file having a different name if this is necessary
for the process as I can do a site-wide rename of every ocurance of that
filename within the source files, but I don't know of any tool or
application that will let me replace the actual files.
Any help or pointers appreciated
Brian Tozer
Use Perl, its regular expression facility to match the filename, and the
File::Find module to iterate through directories and filenames.
You should be able to replace using the same name if you want.

If you actually have the same graphic repeated all over the site, convert to
one instance only, and convert the other
links to the many graphics to a link to the single instance of the graphic
with a relative URL. The URL::URL module might be of help or might not.
Links to perl sites are at: http://www.mbstevens.com/bc.html
....and pull down the 'computing' menu and select CGI/Perl.
The modules needed can be downloaded from CPAN if you don't already have
them.
 
T

Tina - AffordableHOST, Inc.

KiwiBrian said:
I have a need to replace every occurance of a particular graphic file which
occurs in many folders, at several levels, in a site that I have on my hard
drive.
I can tolerate the new file having a different name if this is necessary
for the process as I can do a site-wide rename of every ocurance of that
filename within the source files, but I don't know of any tool or
application that will let me replace the actual files.
Any help or pointers appreciated
Brian Tozer

Rather that create a workaround for this problem, you might consider taking
this opportunity to better organize your website structure. If you have one
graphic, being called from many different files, you should consider putting
the graphic in ONE folder and calling to it in every instance. This will
make changing the graphic a little easier next time around.

--Tina
 
K

KiwiBrian

Tina - AffordableHOST said:
Rather that create a workaround for this problem, you might consider
taking this opportunity to better organize your website structure. If you
have one graphic, being called from many different files, you should
consider putting the graphic in ONE folder and calling to it in every
instance. This will make changing the graphic a little easier next time
around.

Thanks for your help Tina but I do not know of any way of using a common
path to the single graphic file, which I could locate in a subfolder of my
root folder, without the path needing to be different depending on the
hierarchical level of the calling file, and which will work in the site
regardless of whether it is on my Hard Drive, or on my website.
Maybe I am missing something simple.
There are other good reasons peculiar to this application why I have done it
this way, but my original question, and this new one, are both relevant.
Thanks again
Brian Tozer
 
D

David Dorward

KiwiBrian said:
I do not know of any way of using a common
path to the single graphic file, which I could locate in a subfolder of my
root folder, without the path needing to be different depending on the
hierarchical level of the calling file,

Use a root relative URI (i.e. one which starts with a "/")
and which will work in the site
regardless of whether it is on my Hard Drive, or on my website.

Install a web server for local testing. http://httpd.apache.org/
 
N

NOXwebmasterx

KiwiBrian said:
Thanks for your help Tina but I do not know of any way of using a common
path to the single graphic file, which I could locate in a subfolder of my
root folder, without the path needing to be different depending on the
hierarchical level of the calling file, and which will work in the site
regardless of whether it is on my Hard Drive, or on my website.

David's suggestions about this are right. I couldn't live
without an Apache server on my hard drive.


To automate,
In a short perl program, using URI::URL's 'rel()' method:

use File::Find;
use URI::URL;

my $base_url = URI::URL->new('http://www.x.com');
my $abs_url = URI::URL->new('http://www.x.com/images/y.png');
my $rel_url = $abs_url->rel($base_url);

The above can be programmed to iterate with File::Find.
Iterate over all the urls with File::Find,
letting File::Find and a regular expression find new $abs_urls
so that you compute a new $rel_url each time it finds one.
Replace the old $abs_url with a new $rel_url each time.
 
N

NOXwebmasterx

Neal said:
I've considered this. What technical knowledge do I need to accomplish
this? I don't imagine it would install like a M$ product. ;)

Hardly any tech knowledge is needed under windows.
I found it to easier to configure under Win than under Linux.
Download from ActiveState.

Also consider xitami server:
http://www.xitami.com/
if you have fairly simple testing needs.
 
N

NOXwebmasterx

David said:
ActiveState do an Apache installer? I really must spend some time finding
out what we sell...

Silly me. Apache.org. Active State is where you get Perl for Windows.
 
N

Neal

Hardly any tech knowledge is needed under windows.
I found it to easier to configure under Win than under Linux.
Download from ActiveState.

Looking on http://www.activestate.com/ and not figuring out where it is.
The Apache page shows Win32 Binary (MSI Installer):
apache_2.0.52-win32-x86-no_ssl.msi [PGP] [MD5] - which do I need? (W98)
Also consider xitami server:
http://www.xitami.com/
if you have fairly simple testing needs.

I'd prefer Apache, as that's the one I use most often anyhow. Is there any
reason I'd want the 1.3 over the 2.0? The webserver I use is a Unix
running 1.3.26 - if I get things working on a 2.0 will I expect problems?
 
N

NOXwebmasterx

Neal said:
Hardly any tech knowledge is needed under windows.
I found it to easier to configure under Win than under Linux.
Download from ActiveState.

Looking on http://www.activestate.com/ and not figuring out where it is.
The Apache page shows Win32 Binary (MSI Installer):
apache_2.0.52-win32-x86-no_ssl.msi [PGP] [MD5] - which do I need? (W98)

Sorry, Apache.org.
Coffee! Where's my coffee!
I'd prefer Apache, as that's the one I use most often anyhow. Is there any
reason I'd want the 1.3 over the 2.0? The webserver I use is a Unix
running 1.3.26 - if I get things working on a 2.0 will I expect problems?

Probably not for CGI testing. It's setup for PHP might be out of date, but
I'm not sure. You would probably be able to bring it up to date for that
language.
 
N

Neal

Neal said:
The Apache page shows Win32 Binary (MSI Installer):
apache_2.0.52-win32-x86-no_ssl.msi [PGP] [MD5] - which do I need? (W98)

Sorry, Apache.org.
Coffee! Where's my coffee!

Heh. But there are three choices - msi, PGP (a .asc file), and MD5. I have
no idea what any of these are, help? Which one do I want?
Probably not for CGI testing. It's setup for PHP might be out of date,
but
I'm not sure. You would probably be able to bring it up to date for that
language.

Yeah, my server is running an old PHP too. If I set up 2.0 on my machine,
I could install any version of PHP anyhow, I'm guessing. So I imagine I
want 2.0.

See, all the technical information! ;)
 
N

NOXwebmasterx

Neal said:
Heh. But there are three choices - msi, PGP (a .asc file), and MD5. I have
no idea what any of these are, help? Which one do I want?

Depends on which crypto programs you feel more comfortable with. I know you
can get PGP for windows at MIT, and Apache org has some links to
the MD5 utility.
 
N

NOXwebmasterx

Neal said:
See, all the technical information! ;)

Yeah, I don't remember having to go through this
crypto/file-check business when I installed it on Windows
a few years ago. Either it wasn't there, or I just skipped
it and everything worked out anyway.
 
D

David Dorward

Neal said:
Heh. But there are three choices - msi, PGP (a .asc file), and MD5. I have
no idea what any of these are, help? Which one do I want?

MSI is Windows Installer. I don't think Windows 98 comes with Windows
Installer, but you can download it from the Microsoft website.

PGP and MD5 are different ways you can use to check that the MSI file hasn't
been damaged or otherwise altered between the Apache crew creating it and
it arriving on your system.
 
H

Hywel Jenkins

Probably not for CGI testing. It's setup for PHP might be out of date, but
I'm not sure. You would probably be able to bring it up to date for that
language.

Apache doesn't have a setup for PHP. PHP doesn't have one for Apache
either - you have to configure it yourself. PHPTriad is old now, isn't
it (Apache, PHP, and MySQL in one setup).
 
S

Sid Ismail

On Wed, 10 Nov 2004 14:03:10 -0500, "Tina - AffordableHOST, Inc."

:
: : >I have a need to replace every occurance of a particular graphic file which
: >occurs in many folders, at several levels, in a site that I have on my hard
: >drive.
: > I can tolerate the new file having a different name if this is necessary
: > for the process as I can do a site-wide rename of every ocurance of that
: > filename within the source files, but I don't know of any tool or
: > application that will let me replace the actual files.
: > Any help or pointers appreciated
: > Brian Tozer
:
: Rather that create a workaround for this problem, you might consider taking
: this opportunity to better organize your website structure. If you have one
: graphic, being called from many different files, you should consider putting
: the graphic in ONE folder and calling to it in every instance. This will
: make changing the graphic a little easier next time around.


Yes, Tina. Very sensible. :)

Sid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top