Page 1 of 1

[solved] Set "extra2" tag with input data

Posted: 15 Oct 2016 06:09
by xnmp
i set "extra2" column : datatype as "txt" ,label is "name"

i have csv file like this (first column is file path,second column is "name" tag i want to set to "extra2" column
(i can change the csv format to text format and change the separator to something easier to separate such as "****" instead of "space" character)
E:\female\2015_1231_00_50_13_354.png Ana
E:\female\2016_0102_16_33_22_124.png Jamie
E:\female\2016_0103_00_58_57_317.png Irina
E:\female\2016_0105_21_12_17_466.png Hanna V2.4
E:\female\2016_0106_06_16_11_884.png Minami

For more clearly, i want to set
"Ana" extra2 tag to file "E:\female\2015_1231_00_50_13_354.png"
"Jamie" "E:\female\2016_0102_16_33_22_124.png"
and so on ...

is it possible to set "extra2" automatically with input data like this ? (for example ,by scripting ...)
Thanks in advance

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 08:01
by highend
So to get it straight:

You have one file which contains "associations": file + name, delimited via a space
and you want a column to display the name for each file

extra2 column:
Con: Requires you to manually update the tag.dat
database every time your file (that contains the associations) changes.

Pro: Fast, the columns are populated via the tag.dat db


A normal custom column:
Con: Slow, for each displayed entry in the file list, the "csv" file needs to be parsed again

Pro: Always up to date for each file without "manually" updating the tag.dat database

So what do you prefer?

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 08:26
by xnmp
highend wrote:So to get it straight:

So what do you prefer?
Thank you very much for the very detailed information (and for your enthusiasm)
i understand what you wrote clearly
The method i need is the first method (use "extra2" column) , i really appreciate if you could help me to do this method

(i use the csv to set "extra2" tag for multiple file - only once
then if i want to update the "extra2" column, i will do it through xyplorer by the script that you wrote for me viewtopic.php?f=3&t=16212 instead of update the csv file)

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 09:01
by highend

Code: Select all

    $file = "R:\Associations.csv";

    $content = readfile($file);
    foreach($entry, $content, <crlf>, "e") {
        tagitems("ex2", gettoken($entry, 2), gettoken($entry, 1));
    }
    savesettings 64;
Just change the $file variable to point to your local .csv file that contains the associations...

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 09:30
by xnmp
highend wrote:

Code: Select all

    $file = "R:\Associations.csv";

    $content = readfile($file);
    foreach($entry, $content, <crlf>, "e") {
        tagitems("ex2", gettoken($entry, 2), gettoken($entry, 1));
    }
    savesettings 64;
Just change the $file variable to point to your local .csv file that contains the associations...
Thank you very much ,highend ,you made my day
i 'll try it :)

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 10:59
by xnmp
highend wrote:

Code: Select all

    $file = "R:\Associations.csv";

    $content = readfile($file);
    foreach($entry, $content, <crlf>, "e") {
        tagitems("ex2", gettoken($entry, 2), gettoken($entry, 1));
    }
    savesettings 64;
Just change the $file variable to point to your local .csv file that contains the associations...
Hi again,Highend. Thank you so much for the helps

it does not work for me ,i think it because of the separator of my csv file is not the same as i described before
(i'm sorry for that)
When i open the csv with notepad++, it looks like this (separator is comma "," character ) and the filepath also contains "space" character
E:\Program Files\female\2015_1002_23_48_40_653.png,Scarlett
E:\Program Files\female\2015_1010_11_17_15_151.png,Oichi
(i said "space" character before because when i paste the content from csv to notepad++ it become "space" character)

However, because the name and the filepath may contain comma "," character ,i want to change the separator of the script from
<crlf> to special character such as "*" or something ,
so i want to ask if i can change my suggestion/request like this

New Suggestion

1. input file is txt file (simple format)
2. the separator now is * character (for not duplicated with characters of filepath and name)

The new input file (txt, UTF8) will look like this :
E:\Program Files\female\2015_1002_23_48_40_653.png*Scarlett
E:\Program Files\female\2015_1010_11_17_15_151.png*Oichi
could you please re-edit the script for the new input file ?
Thank you very much and sorry for the inconvenient

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 11:24
by highend

Code: Select all

tagitems("ex2", gettoken($entry, 2, "*"), gettoken($entry, 1, "*"));
and edit the $file to "file name.txt" instead of .csv...

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 11:52
by xnmp
highend wrote:

Code: Select all

tagitems("ex2", gettoken($entry, 2, "*"), gettoken($entry, 1, "*"));
and edit the $file to "file name.txt" instead of .csv...
Thank you so much ,it works like a charm
I paste the complete version here for who needed (maybe me in the future :P) (added support reading UTF-8 file)

Code: Select all

 $file = "E:\test\filepathname.txt";

    $content = readfile($file,,,65001);
    foreach($entry, $content, <crlf>, "e") {
        tagitems("ex2", gettoken($entry, 2, "*"), gettoken($entry, 1, "*"));
    }
    savesettings 64;

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 12:13
by highend
readfile() works with UTF-8 / UTF-16LE (both with BOM) without the need to supply the codepage

Re: [help] Set "extra2" tag with input data

Posted: 15 Oct 2016 14:07
by xnmp
highend wrote:readfile() works with UTF-8 / UTF-16LE (both with BOM) without the need to supply the codepage
Thank you for the information, i thought the old code not work with UTF8
Now i see it because of my text file is encoded in UTF-8 without BOM :mrgreen: