Page 1 of 1

pre or post fixed strings presets

Posted: 02 Dec 2017 16:13
by calude
hi

Tidying my pdf invoices I thought of a very fine way to add user defined pre or post string to the pdf's file names

the user builds his prefixes list in list management

then when he wants to add a prefix
selects one file to prefix
hits the keyboard shortcut
a pop up apears with the prefixes list
he clicks on the chosen prefix
the filename is renamed
fast and elegant

Calude

Re: pre or post fix strings presets

Posted: 02 Dec 2017 16:36
by highend
And already possible to do via scripting *scnr* :mrgreen: :ninja: :ball:

Re: pre or post fixed strings presets

Posted: 02 Dec 2017 17:33
by calude
if you have nothing to do..... and are specially bored .... :whistle:
:lol:

Re: pre or post fixed strings presets

Posted: 02 Dec 2017 18:17
by highend

Code: Select all

    $iniFile = self("path") . "\" . self("base") . ".ini";
    if (exists($iniFile) != 1) { status "No .ini file found, aborted!", "8B4513", "stop"; end true; }

    $pre  = regexreplace(getsectionlist("Pre", $iniFile), "^\d+=");
    $pre  = regexreplace($pre, "^(.+?)(?=\r?\n|$)", "$1;$1<::>pre");
    $post = regexreplace(getsectionlist("Post", $iniFile), "^\d+=");
    $post = regexreplace($post, "^(.+?)(?=\r?\n|$)", "$1;$1<::>post");

    $selection = popupmenu("$pre<crlf>-<crlf>$post<crlf>-<crlf>Edit .ini file;edit_ini_file;:cofi", , , , , , <crlf>);
    if (!$selection) { status "No item selected, aborted!", "8B4513", "stop"; end true; }

    if (strpos($selection, "<::>pre") != -1) {
        rename "b", gettoken($selection, 1, "<::>") . "*";
    }
    elseif (strpos($selection, "<::>post") != -1) {
        rename "b", "*" . gettoken($selection, 1, "<::>");
    }
    elseif (strpos($selection, "edit_ini_file") != -1) {
        openwith "Notepad", , $iniFile;
    }
Save it as a script and then create an .ini file with the same base name in the same
folder as your script... Save the .ini file with UTF-16 LE BOM and add these sample
entries:

Code: Select all

[Pre]
1=Me_
2=Myself_
3=Our_

[Post]
1=_After
2=_Then
3=_Later


From then on, edit the .ini file to add / remove your pre- / post items...

Re: pre or post fixed strings presets

Posted: 03 Dec 2017 12:13
by calude
Works like a charm!!!
although I had to find a UTF-16 LE BOM converter as notepad++ didnt seem to have one.
www.fileformat.info

thanks again highend

All the best

Re: pre or post fixed strings presets

Posted: 03 Dec 2017 12:40
by highend
although I had to find a UTF-16 LE BOM converter as notepad++ didnt seem to have one
It has, but it's not called UTF-16 but UCS-2 in Notepad++

Since v18.40.0004 (probably, because it was not officially documented), XY supports
.ini files with UTF-8 / UTF-8 BOM as well

Official support was offered with v18.40.0003 but it only supported getkey and
getsectionlist was added afterwards

So you can use UTF-8 / UTF-8 BOM for the .ini file as well, as long your version
is younger...

As always, thanks for the donation!