Tagging, Searching and Counting

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
TedL1972
Posts: 78
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Hello,
I am picking back up this old thread. I have been using the script below and it works great. I have a question on a possible improvement.

Since this is old I want to remind that this script searches for a document that has a specific tag, let's say "Apple" and verifies if there is already
a folder with the "Apple" name and if not it creates one in a declared directory (E.g. $saveTo = "R:\tst";). If there is already a folder it will copy it in the folder with the same name.

So far I have to do various operations before running the script: 1) tagging the document with all the names, sometimes it may have 15, 20 names;
copy and then instert the tags in the script below; run the script. Several times I do a mistake and the script doesn't run etc.

I was wondering if there is a better and more error proof way to do this. In other words if a script could be used to do the first two operations i.e.
assign the tags to the document and then copy those tags in the script below it would speed up the whole process plus remove possibility of
errors.

One idea I had on this was to either highlight or bold all the names in the document. This would be done manually of course. After that a script could:

a) Search for the highlighted words.
b) Creates tags for that document with those words.
c) Copy and replace the tags in the script below.

Another step which should be done before a) thru c) should be to have a prompt to replace "R:\tst" whenever the documents are supposed to be copied in a differnt directory. I know that this can be done with a "Search & Replace" in a Word document but I was thinking about a search and replace into the actual script without using other applications.

In this way the two manual taks will be reduced to inputing the specific directory name and highlighting the names in the document.

I look forward to any comment on this, thanks.
highend wrote: ↑17 Nov 2018 21:01

Code: Select all

    $saveTo = "R:\tst";
    $tags   = "Banana|Orange|Apple"; // If a file has one of these tags, it will be copied if it doesn't exist under "R:\tst\<name of the tag>"

    $copyList = "";
    foreach($tag, $tags, , "e") {
        $tagged = quicksearch("tags:$tag", "*", , "s");
        foreach($item, $tagged, <crlf>, "e") {
            if ($tag != $lastTag) { $copyList .= "<::>$tag" . <crlf>; }
            $dstFile = trim($saveTo, "\") . "\" . $tag . "\" . gpc($item, "file");
            if !(exists($dstFile)) { $copyList .= $item . <crlf>; }
            $lastTag = $tag;
        }
    }

    if !(regexmatches($copyList, "^([a-z]|\\)")) { status "No new item(s) found!", "8B4513", "stop"; end true; }
    $copyList = formatlist(replace($copyList, "<::>", , , , 1), "e", <crlf>); // Remove the first separator

    setting "BackgroundFileOps", 0;
    $count = gettoken($copyList, "count", "<::>");
    while ($i++ < $count) {
        $section = gettoken($copyList, $i, "<::>");
        $tag = gettoken($section, 1, <crlf>);
        $itemsToCopy = replace(gettoken($section, 2, <crlf>, , 2), <crlf>, "|");
        if ($itemsToCopy) {
            $copyToPath = trim($saveTo, "\") . "\" . $tag;
            copyto $copyToPath, $itemsToCopy, , 2, 2, 1, 1, 0, 0, , 0, 0;
        }
    }
    wait 10;
    status "All new item(s) copied...";
XYPlorer 28.30.0100
Windows 10

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

Re: Tagging, Searching and Counting

Post by highend »

XY can't search for highlighted or bold words in documents so you would need to have an external cli tool to do that. Apart from the fact that you could insert your tags on an input line as well instead of doing that in a document.

Add two input() lines, one for the place to set your destination folder and one for entering your tags?
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 78
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Got it that XYplorer cannot search for highlighted words.

Great idea on the input line. Would you mind suggest the code for that?

Thanks!
XYPlorer 28.30.0100
Windows 10

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

Re: Tagging, Searching and Counting

Post by highend »

Code: Select all

$tags   = replace(trim(input("Enter tag(s)", "Input each tag on a new line!", "Banana<crlf>Orange<crlf>Apple", "m"), <crlf>), <crlf>, "|");
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 78
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

I ran this script both separately and adding to the top of the previous one.

I do get the the prompt window:

Enter tag(s)
Input each tag on a new line!
--------------------------------------
Then the input field below:
--------------------------------------
Banana
Orange
Apple

If I add let's say Pear and Peach under Apple nothing happens.
XYPlorer 28.30.0100
Windows 10

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

Re: Tagging, Searching and Counting

Post by highend »

Why do you think I've included the same three tags in that replacement line like they exist in the original script?
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 78
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Ok, sorry but while I think I understand your point I probably am still doing something wrong.

Here is what I did:

I copied this code

$tags = replace(trim(input("Enter tag(s)", "Input each tag on a new line!", "Banana<crlf>Orange<crlf>Apple", "m"), <crlf>), <crlf>, "|");

on top of the main code from this thread. When I get the input message I replaced the three tags with new ones. Still nothing happened.

:oops: :oops:
XYPlorer 28.30.0100
Windows 10

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

Re: Tagging, Searching and Counting

Post by highend »

How many lines in the original code do you see that begin with $tags = and you are not able to replace one line with another?
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 78
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Ah ah!

I was using both lines of code. I had left the earlier code beginning with $tags - I now replaced it with the new one and it worked!!

Now, could we add a similar line which I guess will be the very first line on top to change the directory, meaning a prompt that asks me wether I want to change the directory where the documents will be saved?
XYPlorer 28.30.0100
Windows 10

TedL1972
Posts: 78
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Never mind I figured it out!

I used the same code and I simply replaced the tags name with the directory name and it worked.

Thanks again Highend!
XYPlorer 28.30.0100
Windows 10

Post Reply