Delete files with a pattern

Find quick help here to get you started with Hollywood
Post Reply
User avatar
Juan Carlos
Posts: 889
Joined: Mon Sep 06, 2010 1:02 pm

Delete files with a pattern

Post by Juan Carlos »

I try to delete files with a pattern but I don't get the correct paramater, I tryed this:
pattern$="*.Log"
DeleteFile(pattern$)
even this:
DeleteFile("dh1:", pattern$) but the solution is worst.
User avatar
Clyde
Posts: 349
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: Delete files with a pattern

Post by Clyde »

Have a closer look to the documentation. The signature of the command is:

Code: Select all

DeleteFile(file$[, callback, userdata, pattern$, matchdir])
It says that file$ has to be a directory in this case. And the way how you do it (pattern$ as second parameter), DeleteFile() assumes pattern$ is the callback, which isn't true obviously.

I can't test the code right now, but I think you have to write:

Code: Select all

pattern$="*.Log"
DeleteFile("dh1:", Nil, {}, pattern$)
I am unsure about Nil or #NIL, but basically you have to pass those other optional parameters, too, so DeleteFile() knows when the pattern occurs.
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
User avatar
Juan Carlos
Posts: 889
Joined: Mon Sep 06, 2010 1:02 pm

Re: Delete files with a pattern

Post by Juan Carlos »

Thank you, I'll test your suggestion because this also is useful for the commands copy and remove.
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Delete files with a pattern

Post by airsoftsoftwair »

Clyde wrote: Tue May 26, 2020 2:43 pm I am unsure about Nil or #NIL, but basically you have to pass those other optional parameters, too, so DeleteFile() knows when the pattern occurs.
Definitely Nil, not #NIL.

@Juan Carlos: Just be very very careful with this command! This command supports full recursion so it can easily kill all files from your HD when called with the wrong parameters or filter patterns ;)
Post Reply