Jump to content

VEX Based Replace File Extension


Recommended Posts

VEX is missing some basic strings features that other languages have.

Here is a way to replace the file extension on a VEX string.

// Replace Redshift .rs file extension with companion .bgeo.sc in the same folder.
// Feed this node to Display only output.
int index = -1;
string left_part = "";
int l = len(s@instancefile);
for (int i=l; i>0; i--) {
    string char = s@instancefile[i];
    if (char == ".") {
        // Found first occurence of . while scanning backwards through string.
        i=0;        // break loop.
if (index != -1) {
    // We have a split point.
    left_part = s@instancefile[:index];
    // Attach alternate file extension for viewport instancing to work.
    s@instancefile = sprintf("%s.bgeo.sc",left_part);



Link to comment
Share on other sites

That can work too but it assumes there is only one period/dot in the provided filename which might not always be the case.

Your posted code can fail on a name like this...

s@file = "thing/another/geom.001.rs";
s@file = concat(join(split(s@file, '.')[:-1],''), ".bgeo.sc");

By scanning backwards through the string I can always be sure the first period I encounter is the correct split point.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...