General structure
The script is formed by five subscripts. Here is the purpose of each of them.
[*]Find Tagged Items: self explanatory. It finds all the tagged items inside a branch, i.e. within a folder and all its subfolders, and shows them in the List in a Find tab.
[*]Transfer Tags from XYplorer to Forks: for each of the items found with the search above, a fork named "$sig.dat" is added, which contains a dump of the tags. The fork is basically a text file in UTF-16LE containing in the first line the label name, in the second line all the tags, and from the third line down the comment.
-
[*]Find Items with Fork: the analogous of the first subscript. Things here a little trickier since there's no "direct" way to find items with a fork, so given a branch for every item the existence of a specific fork is checked via the exist() function. If an item has a fork then the item itself is tagged with a "$sig" tag. Finally a search is triggered to show all the items just tagged in this way, similarly to the first subscript.
[*]Transfer Tags from Forks to XYplorer: again, self explanatory. For each item in the List the fork is read and parsed, and the tag() function is applied accordingly to restore everything.
[*]Delete Fork from Items: does what it says. Deletes the "$sig.dat" from each file in the List.
Usage
When the script is executed you can see all the five routine, two on top and three below. This graphical grouping tells you that the two top subscripts are meant to work together (before a backup), like the three below (before or after a backup).
Typical scenario: you want to backup a whole folder and all its contents. So you browse to that folder and run the first two subscripts. Now every tagged item has its fork, and you can freely copy that folder on another NTFS partitions. The copies will contain the forks as well. In case you now want to remove the forks from the "original" files you simply need to run "Remove Fork from Items".
Another typical scenario: you need to restore those backedup items and the tags as well. In this case first restore the items as you would usually do, then go to the destination containing folder. Finally run in sequence the last three subscripts. That's it!
Tested on
* Windows 7 Ultimate SP1 x64 ITA
Requirements
* XYplorer 11.60.0004 or greater with
- scripting enabled
- permanent variables remembered across sessions
* a NTFS partition
Notes
* I absolutely take no responsibility for whatever damage, direct or indirect, the usage of this script may cause. This code is provided as-is, use at your own risk. You are advised.
* Forks are supported only on NTFS partitions. When transferring a file with a fork from a NTFS partition to a FAT partition only the main stream of the file, i.e. "the file you actually see", is transferred, all the secondary streams (the forks) are not.
* What is $sig? $sig is the variable that contains the basename of the forks. To avoid (unlikely) collisions with other forks name or other tags you are suggested to pick a random name or some sort of hash. Random passwords from https://www.grc.com/passwords.htm are a great choice. Once you have found a suitable name (for example "iS6WykGOsrnq6oXSgESObdjgM8ZxNeqFcXWPvn3PAq6HFqVnaDau8EZpDTBs4be"), type in the Address Bar the following:
Code: Select all
perm $sig; $sig="iS6WykGOsrnq6oXSgESObdjgM8ZxNeqFcXWPvn3PAq6HFqVnaDau8EZpDTBs4be";
* Accessing a fork can be interpreted as a malicious behaviour by your antivirus or HIPS, and the fork itself may be considered dangerous by the mentioned softwares. Of course the forks written by this scripts are absolutely not harmful, since they consist of plain text.
Possible future updates
* -
Changelog
* Rev. 1 / 2012/09/15: the very first version.
Special thanks to...
* admin/Don, for the underlying software, the scripting engine, at least two important updates to the functions used, and his corrections (in other words, everything... ).
Code: Select all
"Find Tagged Items|:find"
goto input ("Find Tagged Items","Find all the tagged items in the following folder and its subfolders (no trailing backslash)",<curpath>,s,,600,400)."\?:lbl:?* or tags:?* or cmt:?* /r";
msg ("The List now shows all the items that can be processed during the next phase.<br>Please select the items that you want to be processed.<br>No processing will take place unless you actively select the next step from the script.",1);
"Transfer Tags from XYplorer to Forks|:fore"
foreach ($item,<get selecteditemspathnames>,<crlf>) {
$info = report ("{Label}<crlf>{Tags}<crlf>{Comment}",$item); //collects the tags of each selected item, placing a new line between them
writefile ("$item:$sig.dat",$info,,"tu"); //writes the gathered info in the fork of each selected item, in UTF
};
-
"Find Items with Fork|:find"
$path = input ("Find Items with Fork","Find all the items having a fork in the following folder and its subfolders (no trailing backslash)",<curpath>,s,,600,400);
$items = folderreport (items,r,$path,r,,);
foreach ($item,$items,<crlf>) {
if (exists ("$item:$sig.dat") != 0) {
tag ($sig,$item,1,0) //add a $sig tag to each item having a fork
};
};
goto "$path\?:tags:"$sig" /r"; //show every item having a fork
msg ("The List now shows all the items that can be processed during the next phase.<br>Please select the items that you want to be processed.<br>No processing will take place unless you actively select the next step from the script.",1);
"Transfer Tags from Forks to XYplorer|:back"
foreach($item,<get selecteditemspathnames>,<crlf>) {
$info = readfile("$item:$sig.dat","t"); //read the info in the fork of each selected item, in UTF
$label = gettoken($info,1,<crlf>); //puts the 1. line of the file in the label variable
tag($label,$item,0); //attaches the content of the label variable as a label
$tags = gettoken($info,2,<crlf>); //puts the 2. line of the file in the tags variable
tag($tags,$item,1,1); //attaches the content of the tags variable as a tag/list of tags
$comment = gettoken($info,3,<crlf>); //puts the 3. line of the file in the comment variable
tag($comment,$item,2); //attaches the content of the comment variable as a comment
};
"Delete Fork from Items|:del"
foreach($item,<get selecteditemspathnames>,<crlf>) {
deletefile "$item:$sig.dat"; //UNDOCUMENTED [http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=8587#p76625]: delete the fork
};