In a GWBasic program I wish to delete all files *.??8 in the working directory AND sub-directories. The 'Kill' command in GWBasic allows no switches and doesn't get into subdirectories. If I shell "del *.??8 /S" (or "del /S *.??8") I get the error message 'Invalid switch -/S'; even though 'del *.??8 /S' (or 'del /S *.??8') works from the DOS prompt. I am using WinXP with all updates. Can anyone tell me how to delete these files from within a Basic program?
Thanks.

Wrong forum.

GWBASIC doesn't have a recursive KILL command. You'll have to write a subroutine that does it yourself.

  1. Use FILES to get all the file names in the target directory.
  2. For each filename:
    • if it is a directory (name is followed by "<DIR>", for example "C:\FOO\MYSUB<DIR>") then recurse.
    • otherwise use KILL
  3. When done, RMDIR the current directory

Remember to specify an error handler or turn it off or use RESUME before trying to delete files (since the OS may disagree and cause an ERROR to be signaled).

I wonder if SHELL "DEL/S ..." would work? The specification specifically refers to COMMAND.COM, which I think isn't supposed to have the /S option. You could also try SHELL "RD/S/Q" (which is an XP command).

Hope this helps.

Thanks Duoas, I'll play around with your advice.
Kanga85

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.