Remove All After

This rename preset requires DOpus 12 (or later).

Overview:

Removes everything after the matched text (not including the fileextension).
Very useful to quickly remove random "garbage" from filenames.

Adds an extra field to the rename dialog where you can type a regular expression:

Anything after the part of the file name which matches the regular expression will be removed.

Example:

If you have the filename This is a test.txt and you enter the regex \bis into the Remove All After field then the resulting filename will be This is.txt.

Download:

Script code:

If you just want to use the script, use the download above. The script code is reproduced here to help people browsing the forum for scripting techniques.

// Remove All After
// Removes everything following the matched regex
/* exported OnGetNewName,OnGetCustomFields */

// adds custom fields to the Rename dialog
function OnGetCustomFields(getCustomFieldData){
  getCustomFieldData.fields.removeallafter='';
  getCustomFieldData.field_labels('removeallafter')='Remove all after'; //jshint ignore:line
  getCustomFieldData.field_tips('removeallafter')='Enter a regular expression to match'; //jshint ignore:line
}

function OnGetNewName(getNewNameData){
  var removeallafter=getNewNameData.custom.removeallafter;
  var name=getNewNameData.newname_stem;
  var re;
  var matches;
  if (name!=''){
    if (removeallafter){
      re=new RegExp(removeallafter,'i');
      matches=re.exec(name);
      if (matches){
        name=name.substr(0,matches.lastIndex);
      }
    }
  }
  return name+getNewNameData.newname_ext;
}
1 Like

thanks for the code
i wanted to remove "from" written character, not "after" it. like i wanna remove from "...eps..." and i type eps, but it keeps the written characters. what should i do?

The built-in Find and Replace is probably all you need.

image

Awesome script, thank you! Would it be possible to edit the script to include in the removal the matched text?

Many thanks, this is very useful. I would like to know more on how to:

  1. remove all after the 8th letter in the file names, what would be the input to key in?
  2. convert this into "Remove all before"

Thanks.

@srmalis @iieeann The standard RegEx mode will be sufficient:

24194.orp

24194b.orp


How to use buttons and scripts from this forum

2 Likes