QB64 Phoenix Edition
Killing files - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Killing files (/showthread.php?tid=3734)

Pages: 1 2


Killing files - PhilOfPerth - 06-05-2025

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?


RE: Killing files - ahenry3068 - 06-05-2025

(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


RE: Killing files - SMcNeill - 06-05-2025

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.


RE: Killing files - bplus - 06-05-2025

or more QBistically and less DOS like:

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


RE: Killing files - RhoSigma - 06-05-2025

Jesus Christ boys, where do you live?

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


RE: Killing files - OldMoses - 06-05-2025

(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


RE: Killing files - ahenry3068 - 06-05-2025

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.


RE: Killing files - PhilOfPerth - 06-05-2025

(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


RE: Killing files - Kernelpanic - 06-05-2025

It's even easier, folks!  Tongue

[Image: Del-Benutzung2025-06-05.jpg]


RE: Killing files - RhoSigma - 06-05-2025

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