Delete files not named x and not in folder named z

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Delete files not named x and not in folder named z

Post by kiwichick »

So I'm tidying up the artwork in my music collection. Over the years I've ended up with all sorts of name for just one image - folder.jpg, artist-album.jpg, album-artist.jpg, etc. I want to get rid of any that aren't named folder.jpg. But, some artists have folders named Singles and I want to leave all jpg files in those folders regardless of name. My music folder structure is as follows:

Code: Select all

MUSIC\
  Artist 1\
    album a
    album b
    singles
  Artist 2\
    singles
  Artist 3\
    album a
    album b
    album c
I'd like to branch view an artist folder (or, ideally, the whole music folder) and delete any jpg that is a) not named folder.jpg AND b) not in a folder named Singles. I have this script at the moment and it works but I can only use it on artists with no Singles folder because it deletes all image files not named folder.jpg:

Code: Select all

	foreach($item, listpane( ,"*.jpg", 1)) {
		$name = gpc($item, "name");
		if ($name != "folder.jpg") {
		selectitems $item;
		delete(1,0);
		}		
    }
I've been trying to figure out how to add !="Singles" but I can't get it to work. I don't know if that's because I've gone about it the wrong way, or if it's something to do with my selectitems code. Here's what I can remember of what I've tried:

Code: Select all

	foreach($item, listpane( ,"*.jpg", 1)) {
		$parent = gpc($item, "parent");
		$name = gpc($item, "name");
		if ($name != "folder.jpg") && ($parent != "Singles") {
			selectitems $item;
			delete(1,0);
		}		
    }

Code: Select all

	foreach($item, listpane( ,"*.jpg", 1)) {
		$parent = gpc($item, "parent");
		$name = gpc($item, "name");
		if ($name != "folder.jpg" && $parent != "Singles") {
			selectitems $item;
			delete(1,0);
		}
	}    

Code: Select all

	
	foreach($item, listpane( ,"*.jpg", 1)) {
		$parent = gpc($item, "parent");
		$name = gpc($item, "name");
		if ($name != "folder.jpg"){
			if ($parent != "Singles") {
				selectitems $item;
				delete(1,0);
			}
		}	
	}
This is frustrating the heck out of me. Can someone please help me out? TIA :-)
Windows 10 Pro 22H2

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

Re: Delete files not named x and not in folder named z

Post by highend »

Why should this be done in a branch view and why should matches be selected before they are deleted?

Code: Select all

    $jpgs   = quicksearch("*.jpg", , , "s");
    $delete = "";
    foreach($jpg, $jpgs, <crlf>, "e") {
        if (gpc($jpg, "base") UnLikeI "folder" && gpc($jpg, "component", -2) UnLikeI "singles") {
            $delete .= $jpg . <crlf>;
        }
    }
    text $delete;
    // delete 1, 0, $delete;
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Delete files not named x and not in folder named z

Post by kiwichick »

highend wrote: 09 Sep 2021 07:09 Why should this be done in a branch view and why should matches be selected before they are deleted?
Thanks so much highend, no particular reason for either except it was code I robbed from another script I have and just altered what I needed to to make it work. I'm not the best at coding so that's usually my method for creating my scripts :lol: Also, at some point I couldn't make it work without the items being selected. Your script seems to be working perfectly. Your help is much appreciated, as always :-)
Windows 10 Pro 22H2

Post Reply