Page 1 of 6 123 ... LastLast
Results 1 to 10 of 59

Thread: How to search and replace file name characters

  1. #1
    Join Date
    Jul 2006
    Beans
    Hidden!

    How to search and replace file name characters

    I have 2 TB of mp3 files in which I need to replace all instances of : and / in the file names within directories three or four levels deep with a dash (-).

    I have no knowledge of any programming language and I'm not sure which tool would be the quickest/easiest to use.

    Is there a simple way to do this?

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,660
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    Hi meanmrmustard.

    There are basically 2 options: use a GUI tool, or a write a custom script. For GUI solutions take a look at pyRenamer and KRename.

    Here's a few tips for scripting:
    • There are 2 main steps:
      • building a regular expression to find the files.
      • creating the command to actually rename the files.
    • Take a look at the command 'find', with the option -exec and the command 'rename' to do the actual renaming

    I would gladly give you more tips, if you post some examples of files you need to rename, and the final result you want.

    Regards.

  3. #3
    Join Date
    Oct 2011
    Location
    ZZ9 Plural Z Alpha
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: How to search and replace file name characters

    A forward slash (/) isn't legal in a filename in Linux or Windows. May want to check again what character you're needing replaced.

  4. #4
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to search and replace file name characters

    As you're running Xubuntu, you probably can use the Bulk Rename feature of Thunar (Xubuntu's default file manager). There's also the thunar-media-tags-plugin that works hand in hand with Bulk Renamer.

    But the command line solution with find and rename is the most versatile.
    Last edited by schragge; March 18th, 2013 at 11:38 PM.

  5. #5
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: How to search and replace file name characters

    Quote Originally Posted by papibe View Post
    Hi meanmrmustard.

    There are basically 2 options: use a GUI tool, or a write a custom script. For GUI solutions take a look at pyRenamer and KRename.

    Here's a few tips for scripting:
    • There are 2 main steps:
      • building a regular expression to find the files.
      • creating the command to actually rename the files.
    • Take a look at the command 'find', with the option -exec and the command 'rename' to do the actual renaming

    I would gladly give you more tips, if you post some examples of files you need to rename, and the final result you want.

    Regards.
    Hello papibe!
    Thanks for the reply.

    I'm looking over pyrenamer now.

    Here is one example:

    KIN: Songs by Mary Karr & Rodney Crowell (2012) FLAC

    This could pass muster if it was KIN - Songs by Mary Karr & Rodney Crowell (2012) FLAC

    Even a white space rather than the ":" would work and it doesn't really matter to me.

    I'm trying to populate my new NAS with my audio but every time it finds a filename like this or the one below it stops, followed by my renaming it manually and then re-starting the transfer.

    Another example:

    Kippington Lodge - Shy Boy/The Complete Recordings 1967-69
    Again either "-" or white space replacing the "/" would resolve the issue.

    I've only begun to learn bash scripting and my progress is slow at best.

    I have a 3 TB disk dedicated to audio files. Some of the top dirs have another directory inside, <album title> inside <Band/Artist name> for instance, so it's two levels deep.
    There may be instances of song names which have colons or slashes in them - not sure about that but they would probably also need to be modified.
    Each colon or slash needs to be changed to another character in order for the NAS software to successfully transfer them to the NAS hard disks.
    Last edited by meanmrmustard; March 19th, 2013 at 12:01 AM.

  6. #6
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to search and replace file name characters

    I guess the slash in the second example is actually DIVISION SLASH (U+2215). Let's try with this code
    Code:
    find Music -type f -exec rename -vn 's/:|∕/-/g' {} +
    The n is there for testing purposes. When you're positive this command works as expected, run it without n to do the actual job. Also, replace Music with the mount point of your 3TB disk.
    Last edited by schragge; March 24th, 2013 at 11:37 PM.

  7. #7
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: How to search and replace file name characters

    Quote Originally Posted by schragge View Post
    I guess the slash in the second example is actually DIVISION SLASH (U+2215). Let's try with this code
    Code:
    find Music -type f -exec rename -vn 's/:|∕/-/g' '{}' +
    The n is there for testing purposes. When you're positive it works as expected, run it without n to do the actual job. Also, replace Music with the mount point of your 3TB disk.
    So if I'm understanding this code it should replace colons and forward slashes with a dash?

    The problem I see is without manually looking at each top level directory after the operation I wouldn't know if it worked or not, not to mention song titles that may or may not contain one or both of the characters.
    Will it also output the result of the operation?

  8. #8
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: How to search and replace file name characters

    Quote Originally Posted by cortman View Post
    A forward slash (/) isn't legal in a filename in Linux or Windows. May want to check again what character you're needing replaced.
    I do understand that but isn't there a distinction between a filename and the name of a directory?

    I've posted two examples to papibe's reply of directory names that are causing the problem.

  9. #9
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to search and replace file name characters

    Quote Originally Posted by meanmrmustard View Post
    Will it also output the result of the operation?
    Yes. The -v in rename -v is a short form of --verbose. This option will print the name of each file being renamed. Similarly, -n is a short form of --no-act. Have a look at the manual page for rename I linked above.

  10. #10
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,660
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    Quote Originally Posted by meanmrmustard View Post
    I've posted two examples to papibe's reply of directory names that are causing the problem.
    Those help, but it would be very useful some actual names, for instance if you could paste the result of a 'ls' command.

    Regards.

Page 1 of 6 123 ... LastLast

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
  •