Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Killing files
#1
I have a folder called RecallHist containing several files with names like "ABC4, ABC6, POP1, POP6, AB1, BD3
and I need to delete those that start with POP (for example).
I've written this code, but the selection$ string is not correct - file is not found.
Code: (Select All)
Name$ = "POP"
Print "Name$ is "; Name$
NewHist:
k = _KeyHit
_Limit 30
If k <> 21248 Then GoTo NewHist '                wait for Delete key
selection$ = "RecallHist/" + Name$ + "?" '    <----------------------------------- this line is wrong - file is not being found
Print "selection$ is "; selection$
If _FileExists(selection$) Then
    Kill selection$ '                            delete files in RecallHist that start with POP plus any other char
    Print "Killed"; selection$ '                  deleted history files for this name
Else
    Print "History still intact" '                not deleted
End If

How do I place a Wildcard in the string?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
(06-05-2025, 04:16 AM)PhilOfPerth Wrote: I have a folder called RecallHist containing several files with names like "ABC4, ABC6, POP1, POP6, AB1, BD3
and I need to delete those that start with POP (for example).
I've written this code, but the selection$ string is not correct - file is not found.
Code: (Select All)
Name$ = "POP"
Print "Name$ is "; Name$
NewHist:
k = _KeyHit
_Limit 30
If k <> 21248 Then GoTo NewHist '                wait for Delete key
selection$ = "RecallHist/" + Name$ + "?" '    <----------------------------------- this line is wrong - file is not being found
Print "selection$ is "; selection$
If _FileExists(selection$) Then
    Kill selection$ '                            delete files in RecallHist that start with POP plus any other char
    Print "Killed"; selection$ '                  deleted history files for this name
Else
    Print "History still intact" '                not deleted
End If

How do I place a Wildcard in the string?
I use this

$IF WINDOWS THEN
      KILLCMD$ = "DEL "
$ELSE
     KILLCMD$ = "rm "
$END IF

Name$ = "POP*"

SHELL _HIDE KILLCMD$ + Name$

I don't believe Wild cards work with the Internal Kill command
Reply
#3
A question mark is a wildcard for one character.  A star is a wildcard for any number of characters.

DIR a?  would work with:
a0
a1
a2

But not:
a01
a02
a03

DIR a* would work with any file that begins with a(anything after).

The * symbol is probably the one you're wanting to use here.
Reply
#4
or more QBistically and less DOS like:

If Ucase$(Left$(filename$, 3)) = "POP" Then Kill filename$
b = b + ...
Reply
#5
Jesus Christ boys, where do you live?

KILL "path/POP*" and be done with it.
Reply
#6
(06-05-2025, 09:30 AM)RhoSigma Wrote: Jesus Christ boys, where do you live?

KILL "path/POP*" and be done with it.
This one gets my vote, one's path to pop stardom is easily killed... Wink
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#7
One reason I use the SHELL method with the Operating system command is that I can also use it to nuke whole directory trees with one Command
WHERE Necessary.

I do believe I was incorrect about the built in KILL command not taking wildcards though.
Reply
#8
(06-05-2025, 09:30 AM)RhoSigma Wrote: Jesus Christ boys, where do you live?

KILL "path/POP*" and be done with it.

The problem with both of these is that the character after POP varies for each file. Kill "path/POP* doesn't accept the * - it doesn't like the * and returns File Not Found.

(06-05-2025, 08:43 AM)bplus Wrote: or more QBistically and less DOS like:

If Ucase$(Left$(filename$, 3)) = "POP" Then Kill filename$

Sorry bplus, I missed your suggestion. I'll give that a go now. Thanks
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#9
It's even easier, folks!  Tongue

[Image: Del-Benutzung2025-06-05.jpg]
Reply
#10
Phil, I hope you did replace "path" in my example with your actual folder specification eg.

KILL "C:\Phil\RecallHist\POP*"

or

KILL "C:\Phil\RecallHist\POP*.txt" to delete only text files starting with POP
Reply




Users browsing this thread: 1 Guest(s)