Announcement

Collapse
No announcement yet.

How to Batch Rename files with two variables?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to Batch Rename files with two variables?

    A while back I read a great tutorial about renaming all of your digital camera photos into a format that is easily searchable. So instead of having thousands of files called, "IMG-0194" or whatever, it suggested naming year-month-date-time.

    So I found the program KRename, and one of the filters was it could read the meta of the photo of when it was originally created, and rename it that.

    So I let that program loose on my entire photo collection, and got everything organized by Year and month. Each folder starts with the year, and there are 12 sub-folders names YEAR-MM (2014-02)

    My daughter has the same growing digital camera collection, so I suggested she do what I did, and she agreed. We set her laptop up to dual boot, and she could rename the pictures on the Windows directory using Krename from Kubuntu.

    Yesterday she goes to access the pictures for the first time, and Windows can't read a single picture! However when we go back to Kubuntu, every picture is there. With that I realize it's a Windows problem and begin to research. I never ran into this program because the only time I know log onto Windows is to play a couple of games.

    I found out that the file name of the picture (2014:01:01 11:39:34.jpg) contains colons, which WINDOWS CAN'T READ!

    So now I've got thousands of pictures that I need to strip the colon out, and replace the space with something else.

    Krename won't rename the pictures with a colon. If I try to add those pictures, it will add 3-4 copies of the same photo. A directory with 160 or so pictures will quickly mushroom to over 3000 pictures to rename.

    So now I have to do this from the command line. I can use the rename command, but I'm having trouble getting the exact syntax to work.

    What I want to do..

    1. Remove the colons from the file name.
    2. Replace the space between the date and time with a dash (-)
    3. Do this for all the pictures in the directory, and sub directories.
    4. Not disturb the MP4 files, which are correctly named (no colons in the file name)

    So I would like to have this..

    Code:
    2014:01:01 11:39:34.jpg
    renamed to this..

    Code:
    20140101-113934.jpg
    Suggestions? Thanks!

    #2
    See Introduction to Sed
    Windows no longer obstructs my view.
    Using Kubuntu Linux since March 23, 2007.
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      The rename command accepts Perl-style regular expressions, which are similar to what you'd use with sed. Testing...
      Code:
      steve@t520:~/junk$ [B]touch "1111:22:33 11:22:33.jpg"[/B]
      steve@t520:~/junk$ [B]touch "4444:55:66 44:55:66.jpg"[/B]
      steve@t520:~/junk$ [B]touch "7777:88:99 77:88:99.jpg"[/B]
      steve@t520:~/junk$ [B]ls -l[/B]
      total 0
      -rw-rw-r--  1 steve steve    0 Feb  8 20:46 1111:22:33 11:22:33.jpg
      -rw-rw-r--  1 steve steve    0 Feb  8 20:46 4444:55:66 44:55:66.jpg
      -rw-rw-r--  1 steve steve    0 Feb  8 20:46 7777:88:99 77:88:99.jpg
      
      steve@t520:~/junk$ [B]rename 's/://g' *.jpg[/B]
      steve@t520:~/junk$ [B]rename 's/ /-/' *.jpg[/B]
      steve@t520:~/junk$ [B]ls -l[/B]
      total 0
      -rw-rw-r--  1 steve steve    0 Feb  8 20:46 11112233-112233.jpg
      -rw-rw-r--  1 steve steve    0 Feb  8 20:46 44445566-445566.jpg
      -rw-rw-r--  1 steve steve    0 Feb  8 20:46 77778899-778899.jpg
      Looks like the two rename commands will work. The first command searches for all colons and replaces them with the empty string (g instructs the parser to match all colons, not just the first one). The second command searches for a space and replaces it with a hyphen.
      Last edited by SteveRiley; Feb 09, 2014, 12:32 AM.

      Comment


        #4
        About KRename

        Code:
        :~$ apt-cache show krename
        Package: krename
        Priority: optional
        Section: universe/utils
        
        Description: powerful batch renamer for KDE
         KRename is a very powerful batch file renamer for KDE which can rename a list
         of files based on a set of expressions. It can copy/move the files to another
         directory or simply rename the input files.
        
        Homepage: http://www.krename.net

        Krename won't rename the pictures with a colon...
        Making few test subjects with the colon - starting the Krename...



        1 - clearing the template
        2 - clicking the 'Insert Part of Filename'
        3 - Painting the 'year' part - cliking ok (repeating 2&3 with the with the month/day/hour/...)



        and the template is there...



        Clicking the ' Finish'.

        Seems to work at here...

        Last edited by Rog132; Feb 09, 2014, 04:41 AM.
        A good place to start: Topic: Top 20 Kubuntu FAQs & Answers
        Searching FAQ's: Google Search 'FAQ from Kubuntuforums'

        Comment

        Working...
        X