QB64 Phoenix Edition
Using shell to delete a file - 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: Using shell to delete a file (/showthread.php?tid=2618)



Using shell to delete a file - PhilOfPerth - 04-24-2024

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?


RE: Using shell to delete a file - a740g - 04-24-2024

"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.


RE: Using shell to delete a file - PhilOfPerth - 04-24-2024

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.


RE: Using shell to delete a file - PhilOfPerth - 04-24-2024

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)?


RE: Using shell to delete a file - a740g - 04-24-2024

(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



RE: Using shell to delete a file - PhilOfPerth - 04-24-2024

(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!


RE: Using shell to delete a file - Pete - 04-25-2024

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


RE: Using shell to delete a file - PhilOfPerth - 04-25-2024

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!"