SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2000
    Location
    Eugene, OR
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm in the process of switching a site over from plain html files to php files. All of the old files will have some php code inserted into them, which means that I need to change the file extension to .php (actually .phtml in my case).

    Is there a way to change the extension of a whole bunch of files at once, so that I don't have to go through and manually change each one?

    Thanks,

    Adam


  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For windows (and msdos), you can type "ren *.html *.phtml" at the command prompt to change just the file extensions, but you will need to use the features of an advanced text editor such as editplus to update the links in the actual files (if you need to do that).

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Under *nix:

    rename .html .php *.html
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or automate it!, this replaces all the .php files in the same directory as the script with .phtml files and makes a copy of the originals in /temp , if you do not want the coppies comment out the mkdir(... and copy($file,"temp/OLD_$file.. lines.

    I tried to use rename() but windows would not let me, but this should work on windows/unix assuming you have write permissions for the directory, & on windows the ,0775 is meaningless!

    <?
    $handle=opendir('.'); //open current directory//
    mkdir("temp",0775);//place to put originals//
    while (false!==($file = readdir($handle))) {
    if ($file != "." && $file != "..") {

    if(substr($file,-4,4)==".php"){// only if they is .php!//
    copy($file,"temp/OLD_$file");//make a copy//
    $yaks=str_replace(".php",".phtml",$file);
    echo $file."-".$yaks;
    copy("$file","$yaks");unlink($file);// copy and delete original //
    }
    }
    }
    closedir($handle);
    ?>

  5. #5
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    123finder i dont think "rename" exists under *unix environment, and if it does, i must have overlooked it, my workstation is *nix ...

    ---------------------
    myONLYhost.com: when you want something MORE

  6. #6
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True!
    I ran it on linux (6.1, I think)
    then I thought it is a basic command!
    Then as you said, I just tested it on SunOS 5.6 (which I believe use Unix), and there is no such command

    So which could do the operation? cp? or mv?
    Thanks for pointing out, Vinay.

    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  7. #7
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vinay, on the SunOS 5.6, I see rename in man, but I couldn't use that command.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  8. #8
    ComDude CryingWolf's Avatar
    Join Date
    Dec 2000
    Location
    I don't know the cat drug it in!!!
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just a quick question??? It has been a while for both dos and unix...

    copy for dos
    cp for unix

    have you tried something like copy *.html *.phtml???

    I don't remember the syntax for unix cp command... Close to the same would be my guess???

    body { background:#000000; color:#000000 }
    HEY, WHO TURNED OUT THE LIGHTS?!?
    Easy come easy go!!!
    CryingWolf

  9. #9
    ComDude CryingWolf's Avatar
    Join Date
    Dec 2000
    Location
    I don't know the cat drug it in!!!
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Acually looking closer at some old unix books I have, it may be mv (move) you need to look at??? but I don't know if you can rename in a batch like that???

    mv *.html *.phtml

    ok try this at your own risk


    mv -i *.html *.phtml


    the -i will prompt ya for an overwrite before overwriting a file... should be safe and warn you before messing up all your files???

    Actually even better I like Firepages script better it will copy the files to a backup dir then rename each file one by one... Safer??? I don't know if it will work in unix you may have to use cp instead of copy???


    <Edited by CryingWolf on 12-23-2000 at 12:29 AM>
    body { background:#000000; color:#000000 }
    HEY, WHO TURNED OUT THE LIGHTS?!?
    Easy come easy go!!!
    CryingWolf

  10. #10
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the copy() command above is a php one so in this case it will be x-platform, I assumed that mkdir,0775 would cause probs under windows but it does not!

    The main prob would be as PeterW pointed out that you also need to update any links in the pages themselves, and only for files that you have renamed, so I suppose you would need to use (in php) ereg_replace() on any links that matched the filenames that you have altered, sounds like quite a bit of fun!

    Happy Xmas from down-under all.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •