Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using shell to delete a file
#1
I need to delete a file from within a programme), and I'm trying to use shell, as in:
Shell "rm C:\qb64pe\myfile"
but I can't get it to work. I've read through the Wiki notes but can't find anything that makes it work. Where am I going wrong?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
"rm" works on Unix-like operating systems. For Windows you'll need to use "del" / "erase".

I'd suggest you use the QB64 intrinsic commands KILL and RMDIR instead, since these are portable across operating systems.
Reply
#3
Thanks @a740g. I tried the "kill option earlier, but must have had the syntax wrong or something; it didn't work.
But I'll try it again now after your advice.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#4
It works! Thank you.
Now, onward and upward!  Big Grin
Is there a function to create a "backup" of a file, (say myfilebak, from myfile)?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#5
(04-24-2024, 08:26 AM)PhilOfPerth Wrote: It works! Thank you.
Now, onward and upward!  Big Grin
Is there a  function to create a "backup" of a file, (say myfilebak, from myfile)?

There are no commands to directly make copies or backup of files. But you could write one with a few lines of code like:

Code: (Select All)
' Copies src to dst
' Set overwite to true if dst should be overwritten if present
SUB CopyFile (src AS STRING, dst AS STRING, overwrite AS _BYTE)
    IF _FILEEXISTS(src) THEN
        IF NOT _FILEEXISTS(dst) OR (_FILEEXISTS(dst) AND overwrite) THEN
            _WRITEFILE dst, _READFILE$(src)
        END IF
    END IF
END SUB
Reply
#6
(04-24-2024, 10:05 AM)a740g Wrote:
(04-24-2024, 08:26 AM)PhilOfPerth Wrote: It works! Thank you.
Now, onward and upward!  Big Grin
Is there a  function to create a "backup" of a file, (say myfilebak, from myfile)?

There are no commands to directly make copies or backup of files. But you could write one with a few lines of code like:

Code: (Select All)
' Copies src to dst
' Set overwite to true if dst should be overwritten if present
SUB CopyFile (src AS STRING, dst AS STRING, overwrite AS _BYTE)
    IF _FILEEXISTS(src) THEN
        IF NOT _FILEEXISTS(dst) OR (_FILEEXISTS(dst) AND overwrite) THEN
            _WRITEFILE dst, _READFILE$(src)
        END IF
    END IF
END SUB

Thanks again.
That code stretched my primitive mind to its fullest extent, but I eventually interpreted it to Phil-ese, to read:

If the original (src) exists, then
 if there’s no backup (dst), or there is a backup but overwrite is set, then copy the src to dst
write the original to backup

Now, to try it!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#7
DOS commands are still a lot of fun to use. DEL is the DOS command to delete a file. BACKUP is used for back up.

For a great resource, go here: https://www.easydos.com/dosindex.html

Pete
Reply
#8
Thanks Pete.
I've finally succumbed to the urge to take the easy way out.
Since the files are only small, I've decided to create a second copy, and whenever I change one, I re-write the backup one from the (changed) original.
Once again, as Mary Poppins said on the day she lost her umbrella and had to use another flotation method, "not very elegant, but it does the job!"
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply




Users browsing this thread: 2 Guest(s)