Page 1 of 1
Identify items that already exist in other pane?
Posted: 24 Apr 2015 17:03
by kunkel321
I already posted this as a 'Wish' here
http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=13849
And maybe it should be a script request on the Scripts sub forum... IDK.
Anyway, my scenario is that I have a bunch of music files (100s) at work and I like to make playlists for VLC Player. I've been using my default "My Music" folder, which is a network drive at my workplace (right pane, in img below). The problem is that the music keeps "skipping out" because of network problems, so now I want to just have all my music files on my local drive (left pane). I already have 175 music files in the local folder (left), and many (most?) are duplicates of ones in the right. To make it even more complicated: The ones on the network (right) are categorized into subfolders. In the image you see the folders, but there are around 1200 music files.
What I'd like to do is identify the ones on the right that already exist on the left, so I can delete them. I'll then 'Rich Copy' my categorized subfolders over so everything is on the left. (The [currently uncategorized] ones on the left will then get moved into subfolders as appropriate.) It occurred to me to just go ahead and copy over, then tell XY to "skip" any duplicates, but I don't think it will notice the duplicates--since they won't land in the same folder...
It seems sensible to do a "Find" all "Media Files" then use the Search Results Tab for a "Sync Select." Then delete the appropriate ones from one side or the other. Sync Select doesn't seem to work on Search Tabs though... Also it doesn't work if I 'expand' the right pane with Branch View.
Any other ideas on how to handle this?
(Incidentally, I've run into this need a couple of times before, when working with image files.. Should I post a script request? I'm happy to step out the logic and steps that need to happen.)
Thanks All.
Re: Identify items that already exist in other pane?
Posted: 24 Apr 2015 18:44
by highend
The steps are rather easy...
a folderreport for the right pane (a quick search would be better because the search depth can be limited)
either create a hash for each found media item (slow for large files!) or use the name (if you didn't change them...) and the raw size to identify them (fast) and compare all items with a listpane() from the left. Not too hard. Have fun
To give you an idea...
This one works with raw byte size + filename as an identifier
$includedFileTypes were set for testing purposes^^
Code: Select all
$includeFileTypes = "*.mp3|*.mp4|*.flac|*.mkv|*.avi|*.exe";
$activePane = folderreport("files:{fullname}::{size RAW}:{name}", "r", get("Path", "a"), , , "|");
$activePane = formatlist($activePane, "f", "|", "$includeFileTypes", "f");
$inactivePane = folderreport("files:{fullname}::{size RAW}:{name}", "r", get("Path", "i"), "r", , "|");
$inactivePane = formatlist($inactivePane, "f", "|", "$includeFileTypes", "f");
$missing = "";
$existing = "";
foreach($file, $inactivePane) {
$fileNameOnly = gettoken($file, 1, "::");
$identifier = regexreplace(regexreplace($file, "([\\\[\]^$.+(){}])", "\$1"), "(.*?::)(.*?)", "$2");
$match = regexmatches($activePane, $identifier);
if !($match) { $missing = $missing . $fileNameOnly . "<crlf>"; }
else { $existing = $existing . $fileNameOnly . "<crlf>"; }
}
text $missing;
text $existing;
Re: Identify items that already exist in other pane?
Posted: 27 Apr 2015 10:49
by highend
So, was that helpful enough that you can work on it further on?
Re: Identify items that already exist in other pane?
Posted: 27 Apr 2015 16:53
by kunkel321
highend wrote:So, was that helpful enough that you can work on it further on?
Thanks Highend !!

I'm back at my office today and am able to try your code. This definitely starts me in the right direction. And, no. No need to calculate hashes. The ultimate goal is to select the duplicate files, so I can delete them. But this is a start. I see it is assessing the "inactive" pane. Oddly, it seems to find more files in the nested (right) pane. But if it's looking for files that are common to both sides, then shouldn't it find the same number of duplicates on either side? I've manually-checked several items that were generated in the list, and it does indeed seem to be working correctly.
Re: Identify items that already exist in other pane?
Posted: 27 Apr 2015 17:13
by highend
It's looking for all defined media files. If compares each found file from the inactive pane (incl. all subfolders's files) with the ones in the current active pane (flat, no files in subfolders).
If you are interested only in duplicates and you want to delete them in the active pane, a minor change allows this:
Code: Select all
$includeFileTypes = "*.mp3|*.mp4|*.flac|*.mkv|*.avi";
$activePane = folderreport("files:{fullname}::{size RAW}:{name}", "r", get("Path", "a"), , , "|");
$activePane = formatlist($activePane, "f", "|", "$includeFileTypes", "f");
$inactivePane = folderreport("files:{fullname}::{size RAW}:{name}", "r", get("Path", "i"), "r", , "|");
$inactivePane = formatlist($inactivePane, "f", "|", "$includeFileTypes", "f");
$delete = "";
foreach($file, $inactivePane) {
$fileNameOnly = gettoken($file, 1, "::");
$identifier = regexreplace(regexreplace($file, "([\\\[\]^$.+(){}])", "\$1"), "(.*?::)(.*?)", "$2");
$match = regexmatches($activePane, $identifier);
if ($match) { $delete = $delete . "<curpath>\" . getpathcomponent($fileNameOnly, "file") . "|"; }
}
delete 1, 0, $delete;
Modifiy the $includedFileTypes variable as you need!
Deletion is done instantly but to the recycle bin. Test it first!
Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 16:37
by kunkel321
Sooo... If I just now pointed both panes to C:/ and set the file type to "*.*", would that be bad?
Just kidding!
Thanks very much for the coding! It got rid of 2GB of junk!
PS: Is it just me, or is xys code more cryptic than VBA? (Not that I really understand either)
Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 16:55
by bdeshi
vba is less beautiful.
Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 16:57
by Stef123
kunkel321 wrote:PS: Is it just me, or is xys code more cryptic than VBA? (Not that I really understand either)
Brothers in arms - glad to hear I am not the only one in this battle. Been trying desperately to gain some foothold. It's not so much that it were too cryptic or arcane. What gets to me is the onslaught of quotes and blanks and parentheses.
Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 17:00
by admin
Has nothing to do with the language.

Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 18:45
by PeterH
Maybe has to do with XY's acceptance of scripting errors?
As long as wrong coding is accepted, even without note, you may "learn" (get used to) wrong syntax. (Why quote, when
$a=Text; works without problem?) Then when you want something a bit different you have no chance to understand why this suddenly doesn't work, though you find no problem.
And if you think it would be so - then it's a real bug. (My problem with <<< in comment!) Long time I thought I would have coded some syntax error, before I believed it could be a bug.
Sorry to repeat this so often

Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 18:56
by admin
Your recent bug was related to a brand-new and radically new feature which is not official yet: include. It's work in progress.
Yes, quoting strings is highly recommended. One day I might make it obligatory.
Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 20:24
by bdeshi
pre-cautionary inquiry: I'm mostly using single-quotes now, there won't be any consequences, right?
Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 21:19
by admin
Single quotes are just fine.
Re: Identify items that already exist in other pane?
Posted: 28 Apr 2015 21:50
by PeterH
SammaySarkar wrote:pre-cautionary inquiry: I'm mostly using single-quotes now, there won't be any consequences, right?
I'd say: sure, there are!
There are, if there are variables inside the quotes: they will not be resolved, but taken as written.
So in sense of quoting both types are OK - in sense of contained variables it's different.
Re: Identify items that already exist in other pane?
Posted: 06 May 2015 14:37
by stts
I use Treecomp to do all my media synchronising. Its simple and awesome. All it does is every which way you can manual synchronize. It color codes the results so I can see at a glance what is where, no matter how much I have. I used it to easily spot the results as I was testing XYplorer scripts. So I was able to spot problems immediately. I assume all this functionality could be built into XYplorer, but simplicity is important. XYplorer has so many features now that I cant easily find half of them. Maybe tab grouping functionality to help simplify its usage. Like a synchronize tab that pops up several panes and all the commands good for synchronizing.
The one feature Treecomp cant do is recognise the same file in different directories in seperate panes. So to sychronize those directories, it deletes the unwanted folder and files in them, and recopies the new directory and all the files in them. Very inefficient when the files were already in the other pane but just in a different directory. It would be way faster to just move the files to sychronize to the source.
http://www.softpedia.com/get/File-manag ... Comp.shtml