I need some help with my delete button code

Here is what i use. The code asks for extra confirmation on certain folders. So far it works alright. But i wonder, why the Delete REMOVECOLLECTION=auto SHIFT RECYCLE bit doesn't work as expected.
I guess, there is some flaw in my code.

@ifpath:(H:\*|(K:\Bilder(|\*))|L:\*|M:\*|N:\*|coll://)
Confirm MSG="Enter '123' to continue!" PW=123
Confirm MSG="wirklich löschen?" "\n" ICON=warning BUTTONS="weitermachen|abbrechen" ITEMS={allfile$}
@Confirm Sicherheitsabfrage|weitermachen|abbrechen
Delete REMOVECOLLECTION=auto
@ifpath:else
Confirm MSG="wirklich löschen?" "\n" ICON=warning BUTTONS="weitermachen|abbrechen" ITEMS={allfile$}
@Confirm zweite Sicherheitsabfrage|weitermachen|abbrechen
@Confirm dritte Sicherheitsabfrage|weitermachen|abbrechen
Delete REMOVECOLLECTION=auto SHIFT RECYCLE

What are you expecting?

What happens instead?

It actually deletes the file in question.

I'm a bit confused by what you're trying to do here.

Do you really want six confirmation messages in one button, using both @confirm and Confirm?

Is Confirm a script command? It's not built-in.

Have you tried simplifying things, to see if the problem is actually the line you think it's on, not one of the others? e.g. If Confirm is a script command then it might be deselecting the file before it gets to the Delete line, or it might be aborting the whole command.

Some user from the forums had helped me with that code, so i guess there is some script. The multiple confirms are ok, i just wonder, why the other part is being ignored. I had those extra confirms because i am using the keyboard a lot, and feel a bit paranoid about accidently deleting very important stuff, if i hit the wrong key, which happened back then. That's why i have requested for those special commands. I will try out some variations, simplifying stuff, to narrow down the source of that issue.

How about cutting back on the edibles on Weedsday? :wink:

Alternatively you could use a script that tells you what you are going to delete:

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
    cmd.deselect = false;

    var deleteMessage = 'Files to be deleted:\n';
    var k = cmd.files.count;

    if (k > 100) {
        deleteMessage += '\n... very very many files: ' + k + '\n\nWatch out!';
    } else {
        for (var e = new Enumerator(cmd.files); !e.atEnd(); e.moveNext()) {
            deleteMessage += '\n' + e.item();
        }
    }

    if (dlg.Request(deleteMessage) == 1) {
        cmd.RunCommand('DELETE QUIET');
    }
}

Delete for Paranoids.dcf (1.4 KB)

Need a sound, time delay, and/or a captcha? Just whistle :sunglasses:

1 Like

Yeah, cool. What would be great, if it would ask me twice (asking just once is for normal paranoids only :wink: ), and if possible, to include a list of paths i can edit manually in the script, since for most of my data i'm not too much worrying about. Only my own photographs and part of my music collection are important, because i only back it up every now and then, so i might suffer, when my clumsy fingers do the wrong thing.

In the meantime i will replace that old script with your version. Thanks a lot!

I just noticed it, i like the part with the "many many files". :smiley:

I had a closer look at the original button and got a bit confused. So I downloaded the Confirm command from here for a more detailed inspection.

Tip: Change MSG="wirklich löschen?" "\n" to MSG="wirklich löschen?\n" and the command will work properly and display all selected files (and not just ask "Proceed?").

Without the Confirm command the button will work normally and only remove files from a collection and not delete them. So somehow the use of Confirm replaces the items in a collection with the real files. I had a look at the JScript of Confirm but couldn't find the cause. Calling Mr @tbone for help!

As for the script above: I'll post a new version with the restriction for certain paths a bit later.

I'm looking forward to it, thanks lxp!

:beers:

Here you go. Happy not-deleting!

// https://resource.dopus.com/t/i-need-some-help-with-my-delete-button-code/35295

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var dlg = clickData.func.Dlg();
    cmd.deselect = false;

    var dangerousFolders = /H:|K:\\Bilder|L:|M:|N:|coll:\/\//i;

    var isDangerous = dangerousFolders.test(String(tab.path));

    if (isDangerous) {
        cmd.RunCommand('Play FILE="/windows\\Media\\Windows Notify System Generic.wav" QUIET');
        var deleteMessage = 'Files to be deleted:\n';
        var k = cmd.files.count;
        if (k > 100) {
            deleteMessage += '\n... very very many: ' + k + ' files.\n\nWatch out!';
        } else {
            for (var e = new Enumerator(cmd.files); !e.atEnd(); e.moveNext()) {
                deleteMessage += '\n' + e.item();
            }
        }
        if (dlg.Request(deleteMessage) == 1) {
            cmd.RunCommand('Delete REMOVECOLLECTION=auto');
        }
    } else {
        cmd.RunCommand('Delete REMOVECOLLECTION=auto SHIFT RECYCLE');
    }
}

Delete for Paranoids.dcf (2.2 KB)

3 Likes

It works great! Just safe enough for me with two warnings. I also like the notify sound. Thanks again, lxp! Very much appreciated. :beers:

2 Likes