Set value for a custom column

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
touchstone_81
Posts: 9
Joined: 14 Jan 2016 09:59

Set value for a custom column

Post by touchstone_81 »

Hi,
I have added an extra column(Extra 1) and named it as 'AltName'.

I would like to populate this 'AltName' column with a string that is part of the selected file name(without the extension).

example:
Filename = My Vendor v7.2 assembly modification.docx Altname = assembly modification
Filename = My Vendor v7.2 parts picker.docx Altname = parts picker

the 'My Vendor' is always a constant and v7.2 is version number that is variable. I would like to extract the portion of the string following the versionnumber and set it as value of 'AltName' column as shown in the example above.
The idea is to select all files in a folder and then set the 'altname' column value via code.

Could somebody give me some pointers on how this could be achieved?

highend
Posts: 14994
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Set value to Extra Column1

Post by highend »

You need a custom column

How to set one up:
From (http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=11375)
1. Went to Tools / Configuration and choose "Custom Columns"
2. Selected an "Undefined" column and edited it
3. Entered a name then choose the type "Script"
4. Pasted the script (line) that highend so graciously posted
Code:
...

5. Important: Choose the item type "Files and Folders"
6. Saved it
7. Back in main window, right clicked on empty column area and choose "Add column"
8. Right clicked newly added column, selected "Select custom column", then choose the one create in step 4
Regarding the script for it:

Code: Select all

if (regexmatches("<cc_base>", "my constant")) {
    return regexreplace("<cc_base>", "^(.*?v[0-9.\s]+)(.*)", "$2");
}
One of my scripts helped you out? Please donate via Paypal

touchstone_81
Posts: 9
Joined: 14 Jan 2016 09:59

Re: Set value to Extra Column1

Post by touchstone_81 »

Hi @Highend thanks for your reply.

as per your instructions I added a 'custom column' from the 'tools - configuration' menu and set the type to script and entered some dummy text as a placeholder for the script.

example:
Filename = My Vendor v7.2 assembly modification.docx
Altname = assembly modification

Filename = My Vendor v7.2 parts picker.docx
Altname = parts picker

highend
Posts: 14994
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Set value to Extra Column1

Post by highend »

The script you need for the cc:

Code: Select all

if (regexmatches("<cc_base>", "my constant")) {
    return regexreplace("<cc_base>", "^(.*?v[0-9.\s]+)(.*)", "$2");
}
One of my scripts helped you out? Please donate via Paypal

touchstone_81
Posts: 9
Joined: 14 Jan 2016 09:59

Re: Set value to Extra Column1

Post by touchstone_81 »

hi @Highend you are awesome !....it worked :).
just 2 lines of code, great stuff.

touchstone_81
Posts: 9
Joined: 14 Jan 2016 09:59

Re: Set value to Extra Column1

Post by touchstone_81 »

Hi
have a follow-up question.
I realized that the custom column script will run everytime regardless of whether a value has already been set or not.

Is there a way to prevent it from running if a value is already present in the custom column cell.

logic along these lines

if(customcolumncell is null){run script} else {do nothing}

highend
Posts: 14994
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Set value to Extra Column1

Post by highend »

No, this can't be done

2 alternatives:

1. In the configure custom column configuration window
Set Trigger to "List" instead of "Browse"
In this case it will limit the "work" to get the values only from the current visible items instead for all list items

2. Write a script that stores all values in the tag.dat database (in an extra column) "once"
and read the values from there instead of always "recalculating" every entry
Pro: Faster / Con: When you rename a file you need to update the tag.dat database
http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=11375
That's a link how something like this can be done
One of my scripts helped you out? Please donate via Paypal

touchstone_81
Posts: 9
Joined: 14 Jan 2016 09:59

Re: Set value to Extra Column1

Post by touchstone_81 »

ah i feared as much :)...anyway I will check that link, thanks again Highend.

highend
Posts: 14994
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Set value for a custom column

Post by highend »

Btw, I've renamed the thread :)
One of my scripts helped you out? Please donate via Paypal

Post Reply