How to write copy/tags to a NEW file

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Zonko
Posts: 10
Joined: 14 Jul 2017 16:14

How to write copy/tags to a NEW file

Post by Zonko »

I'm working on a script to make a new file, and apply the tags of the selected item <curitem> to the new file. Its something like this :

$file=<curitem>;
$newfile = new("<curitem>.deleted.txt");
$tags = tagitems("tags");
tagitems("tags", $tags, $newfile);

Here is the problem - $newfile is newly created, but applying the tags doesn't work. Its feels like the file doesn't actually exist when the tagitems(..) runs.

So end effect is that a new file gets created - it just doesn't have the tags from the existing.

If the file ALREADY exists - this script works to copy the tags over. So I believe my syntax is correct, I'm just experiencing a race condition of trying to apply tags before they can be written. Is there any way to make this work? (preferably in the same script).

$file=<curitem>;
$newfile = "<curitem>.deleted.txt" ;
$tags = tagitems("tags");
tagitems("tags", $tags, $newfile);

jupe
Posts: 2805
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: How to write copy/tags to a NEW file

Post by jupe »

When you create a new file in current folder, orig selection is lost, so you need to make sure tagitems is getting orig tags from a valid filename, eg.

replace this:
$tags = tagitems("tags");

with this:
$tags = tagitems("tags", , $file);

Zonko
Posts: 10
Joined: 14 Jul 2017 16:14

Re: How to write copy/tags to a NEW file

Post by Zonko »

It works! Thank you.

Post Reply