Hello Folks,
I'm interested in learning some scripting within XYplorer. I thought I'd start small.
I'd like to, recursively, from the folder that is currently selected delete all folders that:
contain __worthless__.xml and no other file
are empty
Any help would be appreciated!
Scripting Newbie
Re: Scripting Newbie
Welcome!
This script should do the trick.
Select a target folder and then run this script (you know how, right?)
Look up the functions/commands used here in XY help file for in depth undestanding.
How it works: basically, creates a recursive item list of the selected folder.
Then deletes __worthless__.xml, now these folders become empty.
Then deletes all empty folders (which includes folders made empty in above step)
This script should do the trick.
Code: Select all
// begin if a folder is selected, exists() retunrs 2 for folder
if (exists(<curitem>) == 2) {
$list = trim(folderreport(dirs, r, <curitem>, r, , '|'), '|'); //create |-separated list of items in selected folder
$count = gettoken("$list", 'count', '|'); //count number of items
$counter = 1; $hitlist = '';
//invert itemlist, this makes recursive deletion easier because deeper folders are listed earlier
while ($counter <= $count) {
$hitlist = "$hitlist".'|'.gettoken($list, -$counter,'|'); $counter++;
}
$hitlist = trim($hitlist,'|'); // trim an extra pipe char (|) at the end
// commence fire, I mean deletion
foreach($it, $hitlist, '|') {
// deletes __worthless__.xml
// according to post, this makes the parent folder empty
if exists("$it\__worthless__.xml") {
delete 0, 0, "$it\__worthless__.xml"; // deletes forever, because they're apparently worthless
}
// delete empty folders
// includes folders containing __worthless__.xml because they're empty now
if (listfolder("$it", ,32) == "") { // here, 32 means return count of items
delete 1, 0, "$it"; // deletes to recycle bin
}
}
msg "Done!";
} else { msg "select a folder first."; }
Look up the functions/commands used here in XY help file for in depth undestanding.
How it works: basically, creates a recursive item list of the selected folder.
Then deletes __worthless__.xml, now these folders become empty.
Then deletes all empty folders (which includes folders made empty in above step)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Delete with recursion
In case you weren't thanked for this then... Thank You, Sammay. I needed a way to search through subfolders and recursively delete files named "junk.txt". This fits the bill exactly.
I am surprised that this is so hard (meaning complicated) to achieve. I kept hoping to find something in the "Delete" command that would do it more directly, such as "Delete .\*\junk.txt". That would be nice.
I am surprised that this is so hard (meaning complicated) to achieve. I kept hoping to find something in the "Delete" command that would do it more directly, such as "Delete .\*\junk.txt". That would be nice.
Re: Scripting Newbie
It isn't so "hard".
Switch to branch view and execute that command. Enter your file name (without path). Done.
Branch view because listpane() is so much faster than folderreport
Code: Select all
$delete = input("Enter the file name to delete...", , , , , 400, 250);
if ($delete) { delete 1, 0, listpane(, $delete, 1+8+16); }Branch view because listpane() is so much faster than folderreport
One of my scripts helped you out? Please donate via Paypal
Re: Scripting Newbie
But I need something that will work any time, and can be part of a script that's doing other things as well.
Re: Scripting Newbie
I which case does it not work when being part of another script?But I need something that will work any time, and can be part of a script that's doing other things as well.
Switching to branch view? There is a # command as well. The long way? Replace the listpane with a folderreport...
One of my scripts helped you out? Please donate via Paypal
XYplorer Beta Club