Removing pre-defined characters from filenames?

hey guys i have 100 or so files with the characters 'asimov' at the end, which i want to remove..
i'm using this to remove the 'asimov'
Rename PATTERN="asimov" TO=" " FINDREP

but that leaves a space at the end (maybe there's a better way to do it?)

so i'm then using this expression to remove trailing spaces
Rename PATTERN "(.[^ ])( +)(.[^ .])" TO "\1\3" REGEXP
which works fine

sometimes the filename has beginning spaces, so i added this in as well, for good measure, to remove those if they're there
Rename PATTERN "^ (.*)#" TO "\1" REGEXP

but, after opus removes trailing spaces, it shows the error 'cannot find the file specified' and i have to click the button again, then it removes any existing beginning spaces

is there something i need to add between 'remove trailing spaces' and 'remove beginning spaces' ?

thanks ahead, i am, not too good at this stuff, i usually try to tack my stuff together from things i've learned from other people here

so it looks like this:

Rename PATTERN="asimov" TO=" " FINDREP
Rename PATTERN "(.[^ ])( +)(.[^ .])" TO "\1\3" REGEXP
Rename PATTERN "^ (.*)#" TO "\1" REGEXP

also how could i add in a capitalise? thank you

This RE will remove both "asimov" and any surrounding space:

Old name: \s*(.+?)\sasimov\s(..+)
New name: \1\2

What do you want to capitalize? You can use the Modify capitalization option if it suits your needs.

thanks MrC - it works, but it deletes the file extension also. so if i have a pdf named " (space)exploring the earth and cosmos asimov(space).pdf" it renames it to "exploring the earth and cosmos" (no file extension)

any thoughts anyone?

Sorry, are you using Regular Expression mode? The extension is preserved.

what is 'regular expression mode'?
is it, just putting REGEXP at the end of the line?

That's for the Rename dialog.

For a button:

Rename REGEXP PATTERN "\s*(.+?)\sasimov\s(..+)" TO "\1\2"

MrC, you are a gentleman and a poet, as well as a creature of great beauty :smiley:
it's working perfectly now, trimmed asimov off the end of 75 or so filenames.

if i may: how now could i insert the characters (ebook) to the end of all of the abovementioned files?
and, what would be a good reg expression to capitalize filenames?

i could combine these to make a nice little one-click cleanup button :smiley:

Very kind.

Change TO pattern to : \1 (ebook)\2

Rename REGEXP PATTERN "\s*(.+?)\sasimov\s(..+)" TO "\1 (ebook)\2"

Regular expressions don't have any facility to convert letter case. You'll have to use other DOpus features to do this, or use a rename setting or script in a button.

thank you MrC - could you, show me the expression , or an expression, to remove any beginning/ending spaces, without the inclusion of a character-deleting pattern?

i am trying this for it:

Rename REGEXP PATTERN "(.[^ ])( +)(.[^ .])" TO "\1\3"
Rename REGEXP PATTERN "^ (.*)#" TO "\1"

this does delete ending spaces, but does not delete beginning spaces- why, i have no clue as im not good with this stuff :cry:

too bad there isnt a reference book with the most commonly needed tasks and their regular expressions :stuck_out_tongue:

If you're just trying to learn, do these in the Rename dialog - you can see the previews and it is easier to write / save there.

Old name: \s*(.+?)\s*(..+)
New name: \1\2

And to help you get the case change...

Write the rename via the Rename dialog. Select some of the files you want renamed, and then select Rename. From the Rename dialog, select Type as Regular Expressions, and set the new/old name as:

Old name: \s*(.+?)\sasimov\s(..+)
New name: \1 (ebook)\2

and check the Modify capitalization and the mode you want. Now examine the preview. If this seems correct, Save the Preset, giving it a name. Now, you can Abort, and go ahead and create your button, with the following:

Rename PRESET="your preset name here"

The button will now utilize the saved preset you created to perform the rename. If you want to see the preview or change things before the run, add the keyword ADVANCED to the end of the command above.

thanks alot MrC, working with it :wink:

I used this to capitalize the first letter of each word, it was in another button i made a couple years back
@nodeselect
Rename CASE=allwords
Rename CASE=extlower
Rename PATTERN="Ii" TO="II" FINDREP
@NODESELECT

I combined it with the expression you showed me to remove any leading/trailing spaces
Rename REGEXP PATTERN "\s*(.+?)\s*(..+)" TO "\1\2"

then i have a preloaded button i installed awhile back called"TitleCasePlus" which i can't edit, it cleans up various characters, also deletes trail/beginning spaces, but i don't like the way it capitalizes, so i will use these in this order:

Rename REGEXP PATTERN "\s*(.+?)\s*(..+)" TO "\1\2" removes trail/beginning spaces
Rename autorename PRESET="TitleCasePlus" cleans up the filenames, also spaces, capitalizes
@nodeselect
Rename CASE=allwords
Rename CASE=extlower these lines capitalize first letter of each word, since i cant seem to edit the way titlecaseplus does it
Rename PATTERN="Ii" TO="II" FINDREP
@NODESELECT

so how is that, to get filenames cleaned up? its some shoddy patchwork, i know haha... my opus is always like this..
anything else i may wanna know?
i wonder is there a way to insert some characters of my choosing, into the very end of a file name? somethin like Rename REGEXP PATTERN TO "'whatever'\2"
and i could just edit the button as needed when i had several files that i wanted to append the same text to the ends of
:opussanta:

nevermind that last question- i found the solution in a button i made a year or so ago:

this will, pop up a dialogue box, ask what text you want to insert: this one starts from the end of the filename:

// This script inserts text into the selected file names at the character position you specify
// Last modified by John Zeman on May 8, 2010

Rename TO="{DlgStringS|Enter the number of filename characters from left\n(the text insertion point)\n\n a comma\n\nand then the text to insert|1,}"
@nodeselect

@script vbscript
option explicit

Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )

Dim strNameOnly
Dim strExtension
Dim intComPos ' Location of the leftmost comma in dialog box entry
Dim strText ' Extracted Text from dialog box entry
Dim strCount ' Extracted number (of places from left) from dialog box entry

' If we're renaming a file then remove the extension from the end and save it for later.
if fIsFolder or 0 = InStr(strFileName,".") then
strExtension = ""
strNameOnly = strFileName
else
strExtension = Right(strFileName, Len(strFileName)-(InStrRev(strFileName,".")-1))
strNameOnly = Left(strFileName, InStrRev(strFileName,".")-1)
end if

' Find the leftmost comma
intComPos = InStr(strNewName,",")
if intComPos > 0 then
strCount = Trim(Left(strNewName, intComPos-1))
strText = Right(strNewName,Len(strNewName)-intComPos)
end if

Dim I
Dim Dots
Dots = ""

if CInt(strCount) > 0 then
I = 1
While I < CInt(strCount)
Dots = "." & Dots
I = I+1
Wend
Dots = "(" & Dots & ")"
else
' Character position was not more than 0 - set LeftDots to an invalid value so rename fails
Dots = "(8SCaO4fOzy5hy4Fs2CxBGCPy6oAl2Hp988ZH9C3toox0HWlmOA)"
end if

Dim regex
' Create a RegExp object
Set regex = new RegExp
regex.Pattern = "(.*)" & Dots

strNameOnly = regex.Replace(strNameOnly, "$1" & strText & "$2")
strNewName = strNameOnly & strExtension

End Function

excuse me, i didnt actually create the script, i just meant that i came across said script a year or 2 ago and incorporated it into my opus. credit goes of course to the original creator :wink:

if anyone wants the script that will insert characters from the beginning of filename, rather than the latter as shown above, i can post :wink: