GP SoftwareTwitter
Opus FAQsManualCommandsObjects

RegExp Rename - Renaming to a new folder - problem with spaces

Someone posted rename preset which would rename files into a folder using the filename of the selected file to create the folder. Another user asked for help modifying this preset so that only the first part of the selected files name (up to the first '-') was used in naming the folder.

I can't tell if there's a minor bug in DOpus or if I am as hopeless at RegExp as ever.

The preset I have created is as follows:

Looks fine to me and it shows in the preview below that all will be fine. However this fails - and I think it's because the rename will result in a space at the end of the folder name.

Using "Test-File 01.txt" as the filename works fine.

Can you confirm that this is my fault or is there a buglette in the rename function when the folder name ends in a space please? Creating a folder with the 'createfolder' command always ignores trailing spaces.

Thanks.

You can't really see it but the New Location column would have "Test " in it, since your regex is matching everything before and after the - character, which includes the spaces (if any).

Changing the Old Name to (.+) - (.+) is probably what you want.

Correct - but I was trying to create a button which account for both 'file-test.txt" and "file - test.txt" and then noticed that the rename function fell over if the folder ended with a space.

Windows doesn't allow spaces at the end of folder names. (Well, it does, via a special syntax, but if we let you do that then it'd break the path in almost all other software.)

You could use this to make the spaces optional:

^(.*[^ ]) ?- ?([^ ].*)$

(The ^ and $ at the ends probably aren't needed, but just in case.)

Thanks.

I wonder if it would make sense for the Rename function to either strip trailing spaces from any folder (like the normal createfolder function) or whether the logic here is that the Rename function just mimics what the user asks for - in which case a prompt in the preview of some kind would be of use perhaps.

Probably makes sense for it to strip the spaces, agreed. I guess nobody ran into this before (who reported it, at least!).