Needed - file delete and exists commands
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Needed - file delete and exists commands
I modified my FontView program with a Save button so that the user can search for fonts and save their favourite font names and sizes. But once a file is created, the information keeps appending to the file every time the program is run, unless the user deletes it manually.
I would like to be able to create a fresh file each time FontView is run, but I can’t think of a way to do that. Normally I would use code such as if exists(filename) then filename delete. In SPL I imagine it would look more like ? #.exists(filename), #.delete(filename)
I would like to be able to create a fresh file each time FontView is run, but I can’t think of a way to do that. Normally I would use code such as if exists(filename) then filename delete. In SPL I imagine it would look more like ? #.exists(filename), #.delete(filename)
The only thing that gets me down is gravity...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Needed - file delete and exists commands
Yes, yes. File management functions are next to be done.
Please note that setting file position to the beginning of file makes write functions to write from the beginning (writing over old content):
#.filepos(file,0)
Please note that setting file position to the beginning of file makes write functions to write from the beginning (writing over old content):
#.filepos(file,0)
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Needed - file delete and exists commands
I tried that today. The data wrote into the start of the file, but just appended to the beginning of the old data rather than writing over it.
The only thing that gets me down is gravity...
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Needed - file delete and exists commands
The other issue is that if I include a filepos command for a file before the user has created the file, the program will stop with an error.
But I will curb my enthusiasm and wait patiently for the new file commands.
But I will curb my enthusiasm and wait patiently for the new file commands.
The only thing that gets me down is gravity...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Needed - file delete and exists commands
You can give a program sample to show how it goes.
In this code:
Code: Select all
f = "out.txt"
#.writetext(f,"long text")
#.filepos(f,2)
#.writetext(f,"1234")
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Needed - file delete and exists commands
Of course it is not possible to set position in non-existing file.
Yes, I just wanted to remind about an existense #.filepos function
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Needed - file delete and exists commands
What if instead of an error, filepos for a non-existent file returned the value -1. That would would eliminate the need for an exists command, but is probably the same amount of work for you.
The only thing that gets me down is gravity...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Needed - file delete and exists commands
Currently supposed file function names are:
#.fdelete
#.frename
#.fmove
#.fcopy
#.fexist
These file functions will be renamed:
#.filepos -> #.fpos
#.filesize -> #.fsize
#.eof -> #.fend
#.fdelete
#.frename
#.fmove
#.fcopy
#.fexist
These file functions will be renamed:
#.filepos -> #.fpos
#.filesize -> #.fsize
#.eof -> #.fend
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Needed - file delete and exists commands
I ran your test program six times. Here is my out.txt file:
1234 text
long text
long text
long text
long text
It seems that you get overwrites and I get appends.
1234 text
long text
long text
long text
long text
It seems that you get overwrites and I get appends.
The only thing that gets me down is gravity...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Needed - file delete and exists commands
This is a correct result if to run it many times. Because
Code: Select all
#.writetext(f,"long text")
Code: Select all
#.fpos(f,2)
#.writetext(f,"1234")