Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script to rename files

    Hi,

    I have a problem of renaming a lot of files (mp3's actually) to proper english
    I already have all my files renamed the way I want to, it's just a matter of what should be uppercase/lowercase. I would like to write a Windows script for this purpose.

    All my mp3 files look like this:

    'Artist - 01 - Title.mp3' (all uppercase)

    Below are the rules that apply to "proper" english and the way I want my files to be:

    1. Always capitalize the first and last word of a title/artist.
    -i.e. "Children of Bodom - 01 - For the glory" - note the first letter of the title must also be capitalized, even if it's a word like for, of, in,... (see #2)

    2. Capitalize all words between the first and last word of a title/artist except:
    a, an, the, and, but, or, nor, as, at, by, for, in, of, on, to
    -i.e.

    3. Do not capitalize words like n' o' de' (i.e. "Rock n' Roll")
    -should apply to anywhere in the filename
    -i.e. "de' Facto - 01 - Blabla n' Bloblo"

    I would really like some help here making a script for this to work properly. I would also like for it to have a function to include subfolders.

    If anyone can provide more info on how to do this or maybe has a script like this - major thanks!

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    This thread might help you out: .bat file to remove part of a file name
    OracleGuy

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    There are good tools if you know where to look. Flexible Renamer is one of the best I've tried, and I've tried a few.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Will try that liorean, but I almost finished my script from the link that oracleguy gave me. And I learned a little Javascript inbetween

    The problem I have is that I can't seem to pass several arguments to the split function. What I'm trying to do is something like:

    splitString = fileName.split(" - 01 - " || "- 02 -" || ,...);

    So I would end up with to arrays - artist and title. That didn't work, so I tried with something like this:

    Code:
    for(ind = 0; ind < splitString.length; ind++)
    {
    	if(splitString[ind] == '-')
    	{
    		finalString.slice(0,ind);
    	}
    }
    
    WScript.Echo(finalString);
    Now I would like to know why I don't get any ouput of finalString. There are all kinds of functions on slicing up a string/making it an array, but I don't get any output with them - or what am I doing wrong?


    I will try that program if it does my job.

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    String.prototype.split takes a regex as it's argument. That means you can write something like this:
    Code:
    var
        rTrack=/\s*-\s*\d+\s*-\s*/g,
        sOrig='Artist -4257    -              Song Title',
        aNew=sOrig.split(rTrack); // => ['Artist','Song Title']
    If you want more info on regex in JavaScript, see my sig.
    Last edited by liorean; 04-03-2005 at 05:58 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks liorean, but I took a look at regexp and didn't really understand anything Although your code did trim out the '- 01 -' I needed artist and title in 2 seperate strings. I eventually did it with indexOf for artist - looking up the '- 0' and passing it's position to the substring function and lastIndexOf for title - '1 -' again passing it's location to the substring. Very messy with a lot of if statements but I couldn't understand regexp for the hell of me

    Now that I have artist and title seperated can anyone provide me with some info on how to capitalize first letters of strings with exceptions (for, the, of etc.) and where they appear (if for/of/the is the first or last word it get's capitalized etc).
    I did find some scripts that may be worth modifying but they all use arrays and compare chars, but I'm thinking this would be a lot easier with regex (if I would understand them ) and they don't capitalize a char if it's behind a '(' (i.e. "(for" wouldn't get capitalized.. So if someone knows more about regexp or can give me some hints it would be more than appreciated. The capilazation rules are posted in the first post.

    If not I'm thinking of storing each word in a var and compare it.
    Like:
    if(var1 == for || (for || the,...)
    toUppercase();

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, you're talking with the right person if you need regex help...

    First of all, you were asking for two separate strings. That's exactly what String.prototype.split gave you. It returned an array with two elements in it, the first element being the part of the string before the track number, the second element being the part after the track number. Use hash notation to get the part you want:
    Code:
    var
        sArtist=aNew[0],
        sTitle=aNew[1];
    Doing the capitalisation is trickier because there are a lot of strange cases, and some aren't that very easy to generalise. Still, I'll try helping you with them.

    Code:
    var
        rFirstWordLetter=/\b[a-z]/gi,
        aExceptions= ['a','an','te','de','the','and','but','or','nor','as','at','by',
            'for','in','o','of','on','to','into','onto','is','am','are','isn','don',
            'doesn','haven','hasn','ain','wasn','weren','aren','t','n','that','such'],
    // I split this up so that you don't have that huge of a single line
    // If you prefer a single line, remove aExceptions and rException
    // and instead uncomment this line:
    //      rException=/\b(?:a|an|te|de|the|and|but|or|nor|as|at|by|for|in|o|of|on|to|into|onto|is|am|are|isn|don|doesn|haven|hasn|ain|wasn|weren|aren|t|n|that|such)\b/gi,
    // And remove the whitespace in "have  n".
    // (vBulletin doesn't allow that long unbroken nonwhitespace character sequences)
        rException=new RegExp('\\b(?:'+aExceptions.join('|')+')\\b','gi'),
        sFixedTitle=sTitle
            .replace(rFirstWordLetter,uppercase)
            .replace(rException,lowercase);
    
    
    function lowercase(p){
        return p.toLowerCase();
    }
    
    function uppercase(p){
        return p.toUpperCase();
    }

    Note that this will lowercase all "o", "ain", "don" etc.

    E.g: It will lowercase "don" in not only "don't" but also "Don Quixote". You might want to fine tune it.
    Last edited by liorean; 04-04-2005 at 02:50 AM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #8
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot, that did the trick.


    Now there's only one thing left

    The script shouldn't convert for, of, the etc. if they appear at the start or at the end of the string. I tried the below regex but I can't get it to work (my regex is probably messed up):

    Code:
    rexpOf = /(^of|$of)/g;
    rep = new String ("Of");
    finalTitle = sFixedTitle.replace(rexpOf, rep);
    Oh and another thing. Does the
    Code:
    rFirstWordLetter = /\b[a-z]/gi;
    cover such chars as Š‚ă etc... If you don't see correctly these letters - I am talking about the chars with strange umlauts.

    Thanks again.

    edit: Also I would like it to capitalize of, from,... if they appear as the first or last word inside parantheses i.e. "adasd - 01 -asdasd (Of asdlkajd)".

    Though I can manage without those if it's too much hassle.
    Last edited by Varg Vikernes; 04-04-2005 at 09:06 PM.


  •  

    Posting Permissions

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