Identify items that already exist in other pane?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Identify items that already exist in other pane?

Post 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...

Image

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.
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

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

Re: Identify items that already exist in other pane?

Post 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;
One of my scripts helped you out? Please donate via Paypal

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

Re: Identify items that already exist in other pane?

Post by highend »

So, was that helpful enough that you can work on it further on?
One of my scripts helped you out? Please donate via Paypal

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: Identify items that already exist in other pane?

Post by kunkel321 »

highend wrote:So, was that helpful enough that you can work on it further on?
Thanks Highend !! :biggrin: 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.
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

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

Re: Identify items that already exist in other pane?

Post 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!
One of my scripts helped you out? Please donate via Paypal

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: Identify items that already exist in other pane?

Post by kunkel321 »

Sooo... If I just now pointed both panes to C:/ and set the file type to "*.*", would that be bad? :?
Just kidding! :biggrin:

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)
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Identify items that already exist in other pane?

Post by bdeshi »

vba is less beautiful.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stef123

Re: Identify items that already exist in other pane?

Post 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.

admin
Site Admin
Posts: 66347
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Identify items that already exist in other pane?

Post by admin »

Has nothing to do with the language. :roll:

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Identify items that already exist in other pane?

Post 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 :oops:

admin
Site Admin
Posts: 66347
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Identify items that already exist in other pane?

Post 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.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Identify items that already exist in other pane?

Post by bdeshi »

pre-cautionary inquiry: I'm mostly using single-quotes now, there won't be any consequences, right?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66347
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Identify items that already exist in other pane?

Post by admin »

Single quotes are just fine.

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Identify items that already exist in other pane?

Post 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! :titter:

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.

stts
Posts: 18
Joined: 13 Apr 2006 06:33

Re: Identify items that already exist in other pane?

Post 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

Post Reply