How to bulk change .JPG to .jpg in a directory? (Solved)

Booting, installing, newbie
Post Reply
Message
Author
User avatar
Eastern Counties
Posts: 145
Joined: Tue 31 Jan 2006, 18:09
Location: UK

How to bulk change .JPG to .jpg in a directory? (Solved)

#1 Post by Eastern Counties »

When I download photos from my camera they are given a .JPG extension. Photobucket only seems to recognise .jpg. Is there any way I can bulk change the extension in Rox or Gimp?

Thanks

John

aarf

#2 Post by aarf »

(EDIT: see next posts before you jump into this)
how is your php?
from the php manual, more details at
http://th2.php.net/manual/en/function.rename.php
havent tested it but would assume it would work.
basic code

Code: Select all

<?php
rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");
?>
to iterate through a directory:

Code: Select all

<?php

//changes files in $directory with extension $ext1 to have extension $ext2
//note that if file.ext2 already exists it will simply be over-written
function changeext($directory, $ext1, $ext2, $verbose = false, $testing=true) {
  if ($verbose && $testing) { echo "Testing only . . . <br />";}
  $num = 0;
  if($curdir = opendir($directory)) {
   if ($verbose) echo "Opening $directory . . .<br />";
   while($file = readdir($curdir)) {
     if($file != '.' && $file != '..') {

       $srcfile = $directory . '/' . $file;
       $string  = "$file";
       $str     = strlen($ext1);
       $str++;
       $newfile = substr($string, 0, -$str);
       $newfile = $newfile.'.'.$ext2;
       $dstfile = $directory . '/' . $newfile;

       if (eregi("\.$ext1". '$' ,$file)) { # Look at only files with a pre-defined extension, '$' ensures the ext is only at they end of the filename

         //I think the next two lines are unnecessary but they
         //don't hurt anything so I'm leaving them
         $fileHand = fopen($srcfile, 'r');
         fclose($fileHand);

         if (!$testing) {
            $result=rename($srcfile, $dstfile );
            if (!$result) echo "ERROR renaming $srcfile -> $dstfile<br />";
         }
      

         if ($verbose) echo "$srcfile -> $dstfile<br />";
       }

       if(is_dir($srcfile)) {
         $num += changeext($srcfile, $ext1, $ext2, $verbose, $testing);
       }
     }
   }
   closedir($curdir);
  }
  return $num;
}

$testing=true;
$verbose=true;

//example usages, first run with $testing set to false, then change $testing to true to do them for real:
//changeext('your/directory', 'php', 'html', $verbose,  $testing);
//changeext('your/directory', 'html', 'php',  $verbose, $testing);
?>
Last edited by aarf on Wed 27 May 2009, 14:28, edited 1 time in total.

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#3 Post by puppyluvr »

:D Hello,
Use the bulk renaming feature of Rox...Highlight all the pics, right click, and select rename, and change the suffix to jpg....

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#4 Post by Flash »

Go with puppyluvr, unless you just want to try programming in php. :) I use Rox all the time to bulk change file names. It's fast, easy and the GUI is self-explanatory. I don't know why Windows doesn't include such a feature. :?

aarf

#5 Post by aarf »

puppyluvr wrote::D Hello,
Use the bulk renaming feature of Rox...Highlight all the pics, right click, and select rename, and change the suffix to jpg....
cool

Code: Select all

\.JPG

Code: Select all

.jpg
click "apply" then click "rename"
Attachments
rename.jpg
(38.17 KiB) Downloaded 619 times

User avatar
Eastern Counties
Posts: 145
Joined: Tue 31 Jan 2006, 18:09
Location: UK

#6 Post by Eastern Counties »

Thanks, puppyluvr, Flash & aarf. So it was sitting there all the time - simple when you know how.

Thanks again

John

sky king
Posts: 72
Joined: Wed 08 Apr 2009, 08:42

bulk rename in ROX

#7 Post by sky king »

Nice to know, thanks.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

Re: bulk rename in ROX

#8 Post by Flash »

sky king wrote:Nice to know, thanks.
What's nice to know? :?

kerl
Posts: 154
Joined: Tue 16 Apr 2013, 21:15

#9 Post by kerl »

Is there a way to do it recursively in a number of folders with subfolders?
For example replace .zip to .7z within a tree of directories

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#10 Post by Semme »

Isn't there a "MultiRename" in your menu?
>>> Living with the immediacy of death helps you sort out your priorities. It helps you live a life less trivial <<<

kerl
Posts: 154
Joined: Tue 16 Apr 2013, 21:15

#11 Post by kerl »

Semme wrote:Isn't there a "MultiRename" in your menu?
I'm afraid not.. Just a Filesystem->PRename

I think I tried MultiRename (there is a recent pet in the forum, right?) but did not work on Slacko 6.3.2

I'm afraid I've resorted to wine :oops: namely an app called den4b-renamer which seems to work well with Puppy well.. It cannot be restored after being minimized so in this case you're forced to kill it

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#12 Post by Semme »

Speak up if you don't understand how or from where to use this.
>>> Living with the immediacy of death helps you sort out your priorities. It helps you live a life less trivial <<<

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#13 Post by Flash »

Semme, is there a way to limit this to just a defined set of directories so it doesn't go through the entire computer, changing everything it finds?

I suppose if it were run from a console that had been opened in the directory that contains only the directories to be changed, that might do it. In Rox, the ` key opens a console in the directory Rox is in.

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#14 Post by Semme »

>>> Living with the immediacy of death helps you sort out your priorities. It helps you live a life less trivial <<<

kerl
Posts: 154
Joined: Tue 16 Apr 2013, 21:15

#15 Post by kerl »

Semme wrote:Speak up if you don't understand how or from where to use this.
I don't understand upon what nor from where :) though I'd like to know how to script a bit like you to make a simplified gui imitation of den4b-renamer. I like this renamer because it allows you to build out a list of steps to take when renaming files. So, you could make a step-by-step list of rules to make the changes you need. It has full preview mode so you can be certain exactly what's going to change to what

Post Reply