ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Coding Snack Guidelines

rename files according to a list - not the usual rename - please read on!

<< < (2/4) > >>

TomD101:
Hello timns and Renegade,
I used mp3tag to check for track numbers. Almost every album has missing track info - even if it is only one or two - or double entries with the same track number for different titles. So the tag info is of no use for me.

Directory opus appears to have many fascinating options, but I could not find an option, scripting or not, where to assign filenames from a list which is in another order as the files listed in the directory. I even discovered the tools Series Renamer in the Opus-forum, but all elaborate renamers depend on any kind of numbering within the file in the directory. 

I need a tool to read the string from the file name, compare it to the string in the textfile and, if the same, rename the file in the directory with the filename from the textfile.

This is something I haven't found yet - or didn't use the right terms for my search.

Thomas

Krishean:

list.txt:

--- ---01 Put You in a Song
02 You Gonna Fly
03 All for You
04 Long Hot Summer
05 Without You
06 Georgia Woods
07 Right on Back to You
08 Shut Out the Lights

rename.js:

--- Code: Javascript ---function exit(a){return WScript.Quit(a);}function echo(a){return WScript.Echo(a);} var fso=WScript.CreateObject('Scripting.FileSystemObject'); exit(main());function main(){        var tmp=[];        // read list        if(fso.FileExists('list.txt')){                try{                        var list=safe_split(file_get_contents('list.txt'));                }catch(err){ // there was an error while reading list.txt                        echo('Error: Unable to read list.txt!');                        return 1;                }                // parse list                var rExp=/^(\d+)\s+([ \w\d]+)$/i;                for(var i=0;i<list.length;i++){                        list[i]=trim(list[i]); // trim off excess whitespace from beginning and end of lines                        if(list[i]=='')continue; // don't process blank lines                        if(rExp.test(list[i])){                                var obj=rExp.exec(list[i]);                                tmp.push([obj[1],obj[2]]);                        }                }                list=tmp;                tmp=[];                // read directory                var e=new Enumerator(fso.GetFolder('.').Files);                for(;!e.atEnd();e.moveNext()){                        // don't attempt to rename itself, or list.txt                        if(e.item() == WScript.ScriptFullName ||                          e.item().Name == 'list.txt')continue;                        for(var j=0;j<list.length;j++){                                // compare filename                                if(e.item().Name.indexOf(list[j][1])!=-1){                                        // create the new filename                                        var fname=list[j][0]+' - '+list[j][1]+'.'+                                          fso.GetExtensionName(e.item());                                        tmp.push('"'+e.item().Name+'" => "'+fname+'"');                                        // rename file                                        e.item().Name=fname;                                        break;                                }                        }                }        }else{ // the script wasn't able to find a list.txt file in the current directory                echo('Error: Does list.txt exist in the current directory?');                return 1;        }        // output a message saying whether files were renamed or not        echo(tmp.length>0?'Files that were renamed:\n\t'+          tmp.join('\n\t'):'No files were renamed!');        return 0;} function safe_split(s){return s.replace(/\r\n/g,'\n').replace(/\r/g,'\n').split('\n');}function trim(s){return s.replace(/^\s+/,'').replace(/\s+$/,'');} function file_get_contents(filename){        var ptr=fso.OpenTextFile(filename,1,false);        var str=new String(ptr.ReadAll());        ptr.Close();        return str;}
create the two files in the same directory that you want to rename the files
the format for list.txt is: <number><space><string> just as shown above
run the script and it should work

skwire:
I hope you don't mind, Krish, this is what I came up with for Tom:

Intro:
Tom's Audio Renamer (TAR, for short).   It uses simple regular expressions for matching groups within a filename and allowing the user to use those matched groups to reformat the name.

Download:
http://skwire.dcmembers.com/apps/snacks/TAR.zip

Notes/caveats:

* Pre-populated with a match string and a format string that should work for your files.
* No settings are currently saved.
* Minimal testing so use this app with copies of your files, please.
Usage:

* Drag-n-drop an album's worth of files to the list.
* Adjust the match and format string if necessary.
* Highlight a file in the list and move it up and down with ctrl-up and ctrl-down (or the right click menu).
* Once you have the list in the order you want, click the Rename button.
* Click the "?" button for more help information.
rename files according to a list - not the usual rename - please read on!

cranioscopical:
Nice!

Feel up to enhancements? If so, how about an undo?

skwire:
Real men don't need undo.   :P

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version