Results 1 to 9 of 9

Thread: Any idea?

  1. #1

  2. #2
    Do u want the code in Perl or PHP?

  3. #3
    Join Date
    Jun 2005
    Posts
    531
    How about

    for i in *_*_*.jpg; do echo ${i}; mv ${i} `awk -F"_" '{ print $1 "_" $3 }'`; done

    Throw an echo in front of the mv to see what it'll do before you run it for real.... I just keyed that without testing....

    In case it's hard to read on your screen, the mark before awk is a tick (to the left of the 1 on the keyboard). The {...} section is quoted with half-quotes (next to the Enter key) and there's another tick after the half quote that follows the }. The double quotes are just plain double quotes.

    Good luck!

  4. #4
    was the code in php?

  5. #5
    Join Date
    Jun 2005
    Posts
    531
    Mat2001 said he wanted something in bash....

  6. #6
    Join Date
    Dec 2005
    Posts
    395
    Save this script to a php file, then run from a shell using 'php scriptname.php'.

    PHP Code:
    <?php
    ////Insert path to image folder
    $imageDir '/path/to/file';
    ////Get array of files in directory
    $d dir("$imageDir");
    while (
    false !== ($entry $d->read()))
    {
             
    $images[] = $entry;
    }
    $d->close();
    ////for each file truncate to 8 characters and rename
    for($i=0;$i<sizeof($images);$i++)
    {
            
    $oldFile $images[$i];
            
    $newFile substr("$oldFile",0,8);
            
    $newFile .= ".jpg";
            
    $copyCommand 'mv '.$imageDir.'/'.$oldFile.' '.$imageDir.'/'.$newFile;
            
    exec("$copyCommand");
    }
    ?>
    This should work. Can somebody else double check this for errors?

  7. #7
    Join Date
    Aug 2006
    Posts
    60

    acdsee

    if these files are physically present then just use acdsee the simplest way to do this .

  8. #8
    Join Date
    Jul 2006
    Posts
    34
    eiww... why would u do it in php if the bash D provided need no programming!

  9. #9
    Join Date
    Dec 2005
    Posts
    395
    Because all I know is PHP....

Posting Permissions

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