Needed - file delete and exists commands

User avatar
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: Canada
Contact:

Needed - file delete and exists commands

Post by rbytes »

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)
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Needed - file delete and exists commands

Post by Mr. Kibernetik »

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)

User avatar
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: Canada
Contact:

Re: Needed - file delete and exists commands

Post by rbytes »

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

User avatar
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: Canada
Contact:

Re: Needed - file delete and exists commands

Post by rbytes »

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. :)
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Needed - file delete and exists commands

Post by Mr. Kibernetik »

rbytes wrote:
Thu Sep 28, 2017 5:13 am
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.
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")
the contents of "out.txt" file is "1234 text".

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Needed - file delete and exists commands

Post by Mr. Kibernetik »

rbytes wrote:
Thu Sep 28, 2017 5:18 am
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.
Of course it is not possible to set position in non-existing file.

Yes, I just wanted to remind about an existense #.filepos function :D

User avatar
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: Canada
Contact:

Re: Needed - file delete and exists commands

Post by rbytes »

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. :lol:
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Needed - file delete and exists commands

Post by Mr. Kibernetik »

Currently supposed file function names are:

#.fdelete
#.frename
#.fmove
#.fcopy
#.fexist

These file functions will be renamed:

#.filepos -> #.fpos
#.filesize -> #.fsize
#.eof -> #.fend

User avatar
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: Canada
Contact:

Re: Needed - file delete and exists commands

Post by rbytes »

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.
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Needed - file delete and exists commands

Post by Mr. Kibernetik »

rbytes wrote:
Thu Sep 28, 2017 2:15 pm
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.
This is a correct result if to run it many times. Because

Code: Select all

#.writetext(f,"long text")
appends and

Code: Select all

#.fpos(f,2)
#.writetext(f,"1234")
writes from the beginning of file.

Post Reply