Multi-file replace Query

Discussion in 'HTML' started by KiwiBrian, Nov 10, 2004.

  1. KiwiBrian

    KiwiBrian Guest

    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
    KiwiBrian, Nov 10, 2004
    #1
    1. Advertising

  2. KiwiBrian wrote:

    > 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 {} \;

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Nov 10, 2004
    #2
    1. Advertising

  3. KiwiBrian

    Guest

    KiwiBrian wrote:

    > 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.
    --
    mbstevens
    , Nov 10, 2004
    #3
  4. "KiwiBrian" <> wrote in message
    news:cmtn1h$8ar$...
    >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
    --
    http://www.AffordableHOST.com - Managed, Dedicated and Colo Servers
    http://www.AxisHost.com - High bandwidth Cpanel Hosting Accounts
    Datacenter located in Grand Rapids, Michigan
    Serving the web since 1997
    Tina - AffordableHOST, Inc., Nov 10, 2004
    #4
  5. KiwiBrian

    KiwiBrian Guest

    "Tina - AffordableHOST, Inc." <> wrote in message
    news:...
    >
    > "KiwiBrian" <> wrote in message
    > news:cmtn1h$8ar$...
    >>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.


    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
    KiwiBrian, Nov 10, 2004
    #5
  6. KiwiBrian wrote:

    > 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/

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Nov 10, 2004
    #6
  7. KiwiBrian

    Guest

    KiwiBrian wrote:

    >
    > "Tina - AffordableHOST, Inc." <> wrote in message
    > news:...
    >>
    >> "KiwiBrian" <> wrote in message
    >> news:cmtn1h$8ar$...
    >>>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.

    >
    > 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.
    --
    mbstevens
    http://www.mbstevens.com
    , Nov 10, 2004
    #7
  8. KiwiBrian

    Neal Guest

    On Wed, 10 Nov 2004 19:23:50 +0000, David Dorward <>
    wrote:

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


    I've considered this. What technical knowledge do I need to accomplish
    this? I don't imagine it would install like a M$ product. ;)
    Neal, Nov 10, 2004
    #8
  9. KiwiBrian

    Guest

    Neal wrote:

    > On Wed, 10 Nov 2004 19:23:50 +0000, David Dorward <>
    > wrote:
    >
    >> Install a web server for local testing. http://httpd.apache.org/

    >
    > 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.
    , Nov 10, 2004
    #9
  10. wrote:

    > Download from ActiveState.


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

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Nov 10, 2004
    #10
  11. KiwiBrian

    Guest

    wrote:

    > Replace the old $abs_url with a new $rel_url each time.


    Should have said:
    Replace the old filename in the file with the string in $rel_url each time.
    , Nov 10, 2004
    #11
  12. KiwiBrian

    Guest

    David Dorward wrote:

    > wrote:
    >
    >> Download from ActiveState.

    >
    > 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.
    , Nov 10, 2004
    #12
  13. KiwiBrian

    Neal Guest

    wrote:
    > Neal wrote:
    >> David Dorward wrote:
    >>> Install a web server for local testing. http://httpd.apache.org/

    >> 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.


    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?
    Neal, Nov 10, 2004
    #13
  14. KiwiBrian

    Guest

    Neal wrote:

    > wrote:
    >> Neal wrote:
    >>> David Dorward wrote:
    >>>> Install a web server for local testing. http://httpd.apache.org/
    >>> 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.

    >
    > 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!

    >> 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?


    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.
    , Nov 10, 2004
    #14
  15. KiwiBrian

    Neal Guest

    wrote:
    > Neal wrote:
    >> 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?

    >> 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.


    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! ;)
    Neal, Nov 10, 2004
    #15
  16. KiwiBrian

    Guest

    Neal wrote:

    > 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.
    , Nov 10, 2004
    #16
  17. KiwiBrian

    Guest

    Neal wrote:

    > 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.
    , Nov 10, 2004
    #17
  18. Neal wrote:

    > 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.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Nov 10, 2004
    #18
  19. In article <ubvkd.7044$>,
    says...
    > > 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.


    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).

    --
    Hywel
    Hywel Jenkins, Nov 10, 2004
    #19
  20. KiwiBrian

    Sid Ismail Guest

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

    :
    : "KiwiBrian" <> wrote in message
    : news:cmtn1h$8ar$...
    : >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
    Sid Ismail, Nov 10, 2004
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Krauss
    Replies:
    1
    Views:
    374
    James Stroud
    Jun 20, 2006
  2. Brian Blais
    Replies:
    1
    Views:
    365
    Bruno Desthuilliers
    Jun 27, 2006
  3. Greg Ewing
    Replies:
    2
    Views:
    332
    Dieter Maurer
    Jun 29, 2006
  4. Alun
    Replies:
    3
    Views:
    4,482
    Masudur
    Feb 18, 2008
  5. Prasad S
    Replies:
    2
    Views:
    215
    Dr John Stockton
    Aug 27, 2004
Loading...

Share This Page