Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
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?
Posts: 372
Threads: 23
Joined: May 2022
Reputation:
56
04-24-2024, 06:48 AM
(This post was last modified: 04-24-2024, 06:49 AM by a740g.
Edit Reason: Fixed some typo
)
"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.
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
04-24-2024, 08:14 AM
(This post was last modified: 04-24-2024, 08:25 AM by PhilOfPerth.)
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.
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
04-24-2024, 08:26 AM
(This post was last modified: 04-24-2024, 08:47 AM by PhilOfPerth.)
It works! Thank you.
Now, onward and upward!
Is there a function to create a "backup" of a file, (say myfilebak, from myfile)?
Posts: 372
Threads: 23
Joined: May 2022
Reputation:
56
(04-24-2024, 08:26 AM)PhilOfPerth Wrote: It works! Thank you.
Now, onward and upward!
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
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
04-24-2024, 11:13 AM
(This post was last modified: 04-24-2024, 11:15 AM by PhilOfPerth.)
(04-24-2024, 10:05 AM)a740g Wrote: (04-24-2024, 08:26 AM)PhilOfPerth Wrote: It works! Thank you.
Now, onward and upward!
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!
Posts: 2,179
Threads: 222
Joined: Apr 2022
Reputation:
104
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
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
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!"
|