Delete first word in filename

Hi all, I've searched everywhere and wasn't able to find a renaming script that can delete the first word in a filename. I have a "crop at position" button that someone kindly posted on the forum, but you must specify the number of characters to be cropped. If you want to rename a bunch of files and delete the first word, it can't be done with this button. Does anyone know of any code that can be used to achieve this?

I know I'm stretching, but it would also be great if a script could delete all characters before or after a given character. So for example, if my original filename is "example - movies.txt", I could specify with the script that I wanted to delete all the characters before "movies" so the final result would be "movies.txt", having stripped everything that preceded it. Not sure if anyone has figured it out or if they would find this useful. If anyone has any ideas, please share :slight_smile:

Hi,

although I do not know how to use scripts the screenshot should give you a hint. To change the phrase "movies" you can use a dialog asking the user for the phrase to search for.


Hi xbprm, thanks for the tip :slight_smile: I don't know anything about regular expression, but I tried out the code in your screenshot and it worked. The only thing needed would be some way to automate it like you said, like a popup box where you would input the word (everything before or after it would be deleted). If anyone has any ideas, please share :slight_smile:

Got it :wink: Couldn't stand the challenge

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>New Button</label> <icon1>#newcommand</icon1> <function type="normal"> <instruction>@set keyword= {dlgstring|Enter keyword} </instruction> <instruction>Rename REGEXP PATTERN=&quot;.*{$keyword}(.*)&quot; TO=&quot;{$keyword}\1&quot; AUTORENAME</instruction> </function> </button>

Make a button which runs this to automate that and ask you for the word:

Rename REGEXP PATTERN ".*({dlgstring|Enter string to remove up to}.*)" TO "\1" AUTORENAME

Edit: Oops, posted at the same time as the one above. They both do the same thing. :slight_smile:

BTW, these buttons will both go haywire if the string you type has brackets ( or ) in it. :slight_smile:

But it should work if you use the DOpus escape character ' before every special character, i.e. entering something like '(movies'). Not tested, though :wink:

In regular expressions \ is the escape char, so (movies) should work.

Ofc. there are some other chars that also need escaping, like . and [

[quote="leo"]In regular expressions \ is the escape char, so (movies) should work.

Ofc. there are some other chars that also need escaping, like . and [[/quote]

Correct, ' is for the FAYT field but for RegEx it's the \

You guys are brilliant! Thank you both so much :smiley:

I just stumbled on another post (by Leo) that has a wealth of presets that I never saw before:

[url]Various simple rename presets]

They are all so useful! I accidentally posted a question in the scripting section, so since it relates to the above, I might as well ask it here:

For the "Swap Artists" preset, I changed it so that it would just swap words between a dash (as long as there is only one dash). So for example, if I have a book named "Lewis Carroll - Alice in Wonderland.pdf" it would change it to "Alice in Wonderland - Lewis Carroll.pdf". So I tried the following:

Regexp (.+) - (.+) to \2 - \1

It works, but the problem is that the extension is also swapped, so that it results in:

"Alice in Wonderland.pdf - Lewis Carroll"

Is there anyway for me to change the code so that I can avoid swapping the extension?[/url]

Try this

Regexp (.+) - (.+).(.+) to \2 - \1.\3

xbprm, you just made my day! That is awesome! Seeing the changes you made has made me better understand the way regexp works. Thanks so much :slight_smile: