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:01Code: 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 Beta Club