5 Replies - 593 Views - Last Post: 29 November 2014 - 04:48 PM

#1 miketurn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-November 14

Multiple File Renaming Script - ISSUE 2 - Files Deselect After Rename

Posted 29 November 2014 - 01:47 PM

Hello Everyone,

ISSUE #2

The following script is a multiple file renaming script. Once this script completes the renaming of multiple files the script then deselects all of the files it renames.
Does anyone know of any kind of jscript code that can allow this script to keep the renamed files highlighted after the renaming process is complete?

Thank You very much for taking the time to read this and for any help that may be provided.

I am new here so I am not sure if it is possible, but if someone has a solution for this problem above, is there anyway that the new code added could be in a different color or put in a separate code box just so I can see how this is done, just for learning purposes?
Thanks Again

function OnInit(data){
    data.name = "RenameBaseNameContinueNumbering";
    data.desc = "";
    data.copyright = "";
    data.version = "1.0";
    data.default_enable = false;
    var cmd = data.AddCommand();
    cmd.name = "RenameBaseNameContinueNumbering";
    cmd.method = "DoRenameBaseNameContinueNumbering";
    cmd.desc = data.desc;
    cmd.label = "RenameBaseNameContinueNumbering";
}
//////////////////////////////////////////////////////////////////////////////
function DoRenameBaseNameContinueNumbering(data){
    if (!data.func.sourcetab.selected.count) return;
    DOpus.ClearOutput();
    var thing = new RenameBaseNameContinueNumbering(data);
    thing.rename();
}
//////////////////////////////////////////////////////////////////////////////
function RenameBaseNameContinueNumbering( data){
    this.files = data.func.sourcetab.selected;
    this.numberedFileFound = false;
    this.numberedFileBaseName = '';
    this.firstFileBaseName = '';
    this.nextFileNum = 1;
    //////////////////////////////////////////////////////////////////////////
    this.init = function(){
        var filesEnum = new Enumerator(this.files);
        var number = 0;
        var first = true;
        while (!filesEnum.atEnd() ) {
            var item = filesEnum.item(); filesEnum.moveNext();
            var num = this.numberFromFilename(item.name_stem);
            if (first){
                first = false;
                this.firstFileBaseName = item.name_stem;
            }

            if (num && !this.numberedFileFound){
                this.numberedFileFound = true;
                this.numberedFileBaseName = item.name_stem;
            }

            if ((num+1) > this.nextFileNum)
                this.nextFileNum = num+1;
        }
        return number;
    }
    //////////////////////////////////////////////////////////////////////////
    this.numberFromFilename = function(fileName){
        var match = fileName.match(/[0-9]{1,}/);
        if (match) return parseInt(match[0]);
        return null;
    }//////////////////////////////////////////////////////////////////////////
    this.getBaseName = function(basename){
        var dlg = DOpus.Dlg;
        dlg.window = DOpus.Listers(0)
        dlg.message = "Enter new base name.";
        dlg.title = "Rename"
        dlg.buttons = "Ok|Cancel"
        dlg.max = 128;
        dlg['default'] = basename;
        if (dlg.Show())
            return dlg.input;
        return null;
    }
    //////////////////////////////////////////////////////////////////////////
    this.rename = function(){
        var num = this.nextFileNum;
        var filesEnum = new Enumerator(this.files);

        var basename = this.firstFileBaseName;
        if (this.numberedFileFound) basename = this.numberedFileBaseName;
        basename = basename.replace(new RegExp("(.*?)([0-9, ,\(,\)]{1,}$)"),'$1');
        if (!this.numberedFileFound) basename = this.getBaseName(basename);
        if (!basename) return;

        while (!filesEnum.atEnd() ) {
            var item = filesEnum.item(); filesEnum.moveNext();
            if (!this.numberFromFilename(item.name_stem)){
                var newName = basename+' ('+num+')'+item.ext;
                dout(padRight(item.name,30,' ') + " -> " + newName);
                var cmd = 'RENAME FROM "'+item.realpath+'" TO "'+item.path+'\\'+newName+'"';
                DOpus.NewCommand.RunCommand(cmd);
                num++;
            }
        }
    }
    //////////////////////////////////////////////////////////////////////////
    this.init();
}
//////////////////////////////////////////////////////////////////////////////
function dout(text){
    DOpus.Output(text);
}
//////////////////////////////////////////////////////////////////////////////
function padRight(text,len,chr){
    while(text.length < len)
        text=text+chr;
    return text;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Multiple File Renaming Script - ISSUE 2 - Files Deselect After Rename

#2 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6374
  • View blog
  • Posts: 25,756
  • Joined: 12-December 12

Re: Multiple File Renaming Script - ISSUE 2 - Files Deselect After Rename

Posted 29 November 2014 - 02:10 PM

Java and Javascript are completely different languages (JScript suggests a slightly different language as well). Topic moved to the Javascript forum.

But perhaps this is running from a Java web-framework? Please confirm if so.

This post has been edited by andrewsw: 29 November 2014 - 02:11 PM

Was This Post Helpful? 0
  • +
  • -

#3 miketurn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-November 14

Re: Multiple File Renaming Script - ISSUE 2 - Files Deselect After Rename

Posted 29 November 2014 - 02:11 PM

Hello Everyone,

ISSUE #1

The following script is a multiple file renaming script for a file explorer that I am testing. Once this script completes the renaming of multiple files, if you try to undo the rename an error pops up because the way this script handles the rename is it considers the action as a "move" command as if the file has been moved as opposed to renamed.
I have been informed that this issue could be fixed by adding the path of the files renamed (which does not change because the files stay in the same folder).

Does anyone know of any kind of jscript code that can be added that supplies the current path of files that are renamed with this script below? I am aware that this question may be confusing, I just don't know if the piece of code I am looking for is a common jscript code that someone would know what I am talking about, or not.

Thank You very much for taking the time to read this and for any help that may be provided.

I am new here so I am not sure if it is possible, but if someone has a solution for this problem above, is there anyway that the new code added could be in a different color or put in a separate code box just so I can see how this is done, just for learning purposes? Thanks Again

function OnInit(data){
    data.name = "RenameBaseNameContinueNumbering";
    data.desc = "";
    data.copyright = "";
    data.version = "1.0";
    data.default_enable = false;
    var cmd = data.AddCommand();
    cmd.name = "RenameBaseNameContinueNumbering";
    cmd.method = "DoRenameBaseNameContinueNumbering";
    cmd.desc = data.desc;
    cmd.label = "RenameBaseNameContinueNumbering";
}
//////////////////////////////////////////////////////////////////////////////
function DoRenameBaseNameContinueNumbering(data){
    if (!data.func.sourcetab.selected.count) return;
    DOpus.ClearOutput();
    var thing = new RenameBaseNameContinueNumbering(data);
    thing.rename();
}
//////////////////////////////////////////////////////////////////////////////
function RenameBaseNameContinueNumbering( data){
    this.files = data.func.sourcetab.selected;
    this.numberedFileFound = false;
    this.numberedFileBaseName = '';
    this.firstFileBaseName = '';
    this.nextFileNum = 1;
    //////////////////////////////////////////////////////////////////////////
    this.init = function(){
        var filesEnum = new Enumerator(this.files);
        var number = 0;
        var first = true;
        while (!filesEnum.atEnd() ) {
            var item = filesEnum.item(); filesEnum.moveNext();
            var num = this.numberFromFilename(item.name_stem);
            if (first){
                first = false;
                this.firstFileBaseName = item.name_stem;
            }

            if (num && !this.numberedFileFound){
                this.numberedFileFound = true;
                this.numberedFileBaseName = item.name_stem;
            }

            if ((num+1) > this.nextFileNum)
                this.nextFileNum = num+1;
        }
        return number;
    }
    //////////////////////////////////////////////////////////////////////////
    this.numberFromFilename = function(fileName){
        var match = fileName.match(/[0-9]{1,}/);
        if (match) return parseInt(match[0]);
        return null;
    }//////////////////////////////////////////////////////////////////////////
    this.getBaseName = function(basename){
        var dlg = DOpus.Dlg;
        dlg.window = DOpus.Listers(0)
        dlg.message = "Enter new base name.";
        dlg.title = "Rename"
        dlg.buttons = "Ok|Cancel"
        dlg.max = 128;
        dlg['default'] = basename;
        if (dlg.Show())
            return dlg.input;
        return null;
    }
    //////////////////////////////////////////////////////////////////////////
    this.rename = function(){
        var num = this.nextFileNum;
        var filesEnum = new Enumerator(this.files);

        var basename = this.firstFileBaseName;
        if (this.numberedFileFound) basename = this.numberedFileBaseName;
        basename = basename.replace(new RegExp("(.*?)([0-9, ,\(,\)]{1,}$)"),'$1');
        if (!this.numberedFileFound) basename = this.getBaseName(basename);
        if (!basename) return;

        while (!filesEnum.atEnd() ) {
            var item = filesEnum.item(); filesEnum.moveNext();
            if (!this.numberFromFilename(item.name_stem)){
                var newName = basename+' ('+num+')'+item.ext;
                dout(padRight(item.name,30,' ') + " -> " + newName);
                var cmd = 'RENAME FROM "'+item.realpath+'" TO "'+item.path+'\\'+newName+'"';
                DOpus.NewCommand.RunCommand(cmd);
                num++;
            }
        }
    }
    //////////////////////////////////////////////////////////////////////////
    this.init();
}
//////////////////////////////////////////////////////////////////////////////
function dout(text){
    DOpus.Output(text);
}
//////////////////////////////////////////////////////////////////////////////
function padRight(text,len,chr){
    while(text.length < len)
        text=text+chr;
    return text;
}

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6374
  • View blog
  • Posts: 25,756
  • Joined: 12-December 12

Re: Multiple File Renaming Script - ISSUE 2 - Files Deselect After Rename

Posted 29 November 2014 - 02:16 PM

Quote

I am new here so I am not sure if it is possible, but if someone has a solution for this problem above, is there anyway that the new code added could be in a different color or put in a separate code box just so I can see how this is done, just for learning purposes?

This is against the forum rules. We won't just provide you with code.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6374
  • View blog
  • Posts: 25,756
  • Joined: 12-December 12

Re: Multiple File Renaming Script - ISSUE 2 - Files Deselect After Rename

Posted 29 November 2014 - 02:19 PM

Moved to the Javascript forum.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12147
  • View blog
  • Posts: 45,157
  • Joined: 27-December 08

Re: Multiple File Renaming Script - ISSUE 2 - Files Deselect After Rename

Posted 29 November 2014 - 04:48 PM

Merged related threads.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1