quicksearch delete current folder during script execution

Discuss and share scripts and script files...
Post Reply
burgyman
Posts: 4
Joined: 03 Jun 2022 13:22

quicksearch delete current folder during script execution

Post by burgyman »

Hi all,

I'm dealing with a script that is driving me crazy, searched a lot in the forum and went through the quicksearch() documentation but can't find a workaround.

I have a script to search for folders and files and clean up the garbage, short example below:

msg "Proceed with garbage clean up?", 48 + 1;

// Search for files
$files = <<<EOF
Crashpad*
BrowserMetrics*
debug.log
EOF;

status "Searching files...";
foreach($file, $files, <crlf>, "e") {
$file_found = quicksearch($file . " /w", "C:\Users\MyUser\AppData\Local\AppXYZ");
if ($file_found != "") {
// Deletes files
status "Deleting " . $file_found;
delete 0, 0, $file_found;
}
}
status "Clean garbage done!";


During execution of the script, if use double-click to go up 1 folder or navigate somewhere else on the tree, visible files on the list view are also picked up from search for deletion.
Almost deleted an entire critical folder.

What can be possibly wrong with the above?

Many thanks!

burgyman
Posts: 4
Joined: 03 Jun 2022 13:22

Re: quicksearch delete current folder during script execution

Post by burgyman »

Is it possible that the behavior above is a bug with quicksearch()?
I don't understand why an interaction on the UI would interfere with a specific list of files for search.
Is there an alternative to quicksearch?
Thanks.

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

Re: quicksearch delete current folder during script execution

Post by admin »

Before I dive into it:

1) Combining wildcard * with /w seems weird. I don't think this will return any matches.

2) delete 0, 0, ... ?? You are asking for disaster... :roll:

burgyman
Posts: 4
Joined: 03 Jun 2022 13:22

Re: quicksearch delete current folder during script execution

Post by burgyman »

Thanks for the follow-up.

Actually I'm quite unexperienced using scripts and was trying to create one to delete temporary & garbage files based on research in the forum.
The information about quicksearch() in the scripting documentation is quite limited considering how powerful the command actually is (/w is not documented for example).
I have come across that using * in some filenames and /w worked for my use case (delete garbage files before online backup with limited space).

Sample list below:
// Search for files
$files = <<<'EOF'
Crashpad*
BrowserMetrics*
debug.log
af.pak
am.pak
ar.pak
az.pak
be.pak
bg.pak
bn.pak
ca.pak
cs.pak
da.pak
de.pak
de-CH.pak
el.pak
en-GB.pak
eo.pak
es.pak
es-419.pak
es-PE.pak
et.pak
eu.pak
fa.pak
fi.pak
fil.pak
fr.pak
fy.pak
gd.pak
gl.pak
gu.pak
he.pak
hi.pak
hr.pak
hu.pak
hy.pak
id.pak
io.pak
is.pak
it.pak
ja.pak
ja-KS.pak
jbo.pak
ka.pak
kab.pak
kn.pak
ko.pak
ku.pak
lt.pak
lv.pak
ml.pak
mk.pak
mr.pak
ms.pak
nb.pak
nl.pak
nn.pak
pa.pak
pl.pak
pt-BR.pak
pt-PT.pak
ro.pak
ru.pak
sc.pak
sk.pak
sl.pak
sq.pak
sr.pak
sr-Latn.pak
sv.pak
sw.pak
ta.pak
te.pak
th.pak
tr.pak
uk.pak
vi.pak
zh-CN.pak
zh-TW.pak
EOF;

Searching for es.pak without /w would also delete resources.pak which was not intended.

Regarding delete 0, 0, ... yes risky but it should be pretty harmful if it deletes only the files I don't need.

What I still don't understand is why quicksearch() would pick any other files besides what I ask it to loop through the list above.

Any explanation for that? Thanks.

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

Re: quicksearch delete current folder during script execution

Post by admin »

Code: Select all

Crashpad*
BrowserMetrics*
those two will not match anything with /w.

No, I cannot explain that. I cannot reproduce it here. :|

PS: The current beta has some changes that should prevent you from certain risky activities while the SC quicksearch() is busy.

burgyman
Posts: 4
Joined: 03 Jun 2022 13:22

Re: quicksearch delete current folder during script execution

Post by burgyman »

Tested the latest beta on a clean install.
Now if I double-click to move up, the script stops with status message "Script terminated by Esc"
It's safer but not ideal since it prevents the user from doing anything else while a script is running, otherwise it stops.

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

Re: quicksearch delete current folder during script execution

Post by admin »

Can't help it. It all runs in the same thread.

Post Reply