Leading / trailing spaces in variables

Hi

Spaces in variable

I created a button that add trailing number to files or folders so that for example: "test.mp3" files or "test" folders results "test - 01.mp3" and "test - 01" and so on.

I had to use variables so that it works for files as well as folders. Plus variables allows to choose options order:

@nodeselect @runonce:@set num={dlgstring|Enter leading number|01} @runonce:@set sep={dlgstringS|Enter a separator, a space or nothing|" - "} Rename TYPE=files NUMBER {$num} REGEXP PATTERN="(.*)(\.[^.]+)$" TO="\1{$sep}[#]\2" autorename Rename TYPE=dirs NUMBER {$num} REGEXP PATTERN="(.*)" TO="\1{$sep}[#]" autorename

But spaces filled in alone or around a separator such as [ - ] aren't taken into account in the new name, I get "test-01.mp3" instead of "test - 01.mp3". Tough, {$sep} = [ - ] and not [-].

So I have to change

... TO="\1{$sep}[#]\2" ...

into

... TO="\1 {$sep} [#]\2" ...

It's not logical because this code works:

@nodeselect Rename TYPE=files NUMBER {dlgstring|Enter leading number|01} REGEXP PATTERN="(.*)(\.[^.]+)$" TO="\1{dlgstringS|Enter a separator, a space or nothing|" - "}[#]\2" autorename

Conclusion of my various tests: variables don't take in account leading and trailing spaces.

Do I do something wrong here ?

Who will take up the challenge to get their hands dirty ?
Unless it's a bug. In this case advanced users need to confirm it.
You can do it ! :wink:

Your conclusion is correct. The behavior has less to do with the {dlgstringS} dialog and more to do with the @set directive, which ignores leading and trailing spaces. The only way around it, at least for your purpose above, is to go back to using the dialog in-line in the Rename command, without the variable.

You may want to file a request with GPSoftware (see link in my signature). Provide a link to this thread in your report.

You can work around it with this command:

@nodeselect @set num={dlgstring|Enter leading number|01} @set sep=\1{dlgstringS|Enter a separator, a space or nothing|" - "}[#] Rename TYPE=files NUMBER {$num} REGEXP PATTERN="(.*)(\.[^.]+)$" TO="{$sep}\2" autorename Rename TYPE=dirs NUMBER {$num} REGEXP PATTERN="(.*)" TO="{$sep}" autorename

I moved the \1 and [#] into the {$sep} variable so it no longer has a space at the start or end.

(It's not important but I also removed the two @runonce: too as they're not needed with the @set command.)

[quote="leo"]@nodeselect @set num={dlgstring|Enter leading number|01} @set sep=\1{dlgstringS|Enter a separator, a space or nothing|" - "}[#] Rename TYPE=files NUMBER {$num} REGEXP PATTERN="(.*)(\.[^.]+)$" TO="{$sep}\2" autorename Rename TYPE=dirs NUMBER {$num} REGEXP PATTERN="(.*)" TO="{$sep}" autorename[/quote]

Bravo ! :open_mouth:
It works :smiley: