Hey
I need to do some file stuff...
I need to create a new file... but if it exists... I want to add a new line...
I don't have anything this far yet...
grtz
file thing
- Seb McClouth
- Veteran
- Posts: 342
- Joined: Wed Nov 09, 2005 7:47 am
- Location: Inside the Matrix...
- Contact:
file thing
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
- Seb McClouth
- Veteran
- Posts: 342
- Joined: Wed Nov 09, 2005 7:47 am
- Location: Inside the Matrix...
- Contact:
How can someone check if the file is new or existing?
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
- Seb McClouth
- Veteran
- Posts: 342
- Joined: Wed Nov 09, 2005 7:47 am
- Location: Inside the Matrix...
- Contact:
it matters because the program is deleting a file and recreating it... for that reason I need.
Thx Sid I'll ask him.
Thx Sid I'll ask him.
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
**********************************************************
Hey Moneo
Hows you? Me doing great.
I have question and Sid6.7 told me you might be some help.
For a program I need to remove a file, create a new one, and add lines to the file.
But the adding thing is kinda blury, because first I need a check to see if the file is empty or already contains some text. If it does contain text I need to put the new text after the old one.
You think you can help me on this one?
grtz
Seb
**********************************************************
Hi Seb,
I got your above message on PM. I'm posting my reply here because other people have already posted stuff.
In your first post you said: "I need to create a new file... but if it exists... I want to add a new line..."
In your last post you also said: "it matters because the program is deleting a file and recreating it... for that reason I need."
Sid6.7 says I helped on the DEEBEE program to check for an existing file. I checked this program and there's no "file exist" logic there. I wrote a subroutine to "delete" a file by opening it for output and closing it, which makes it a zero-length-file.
Anyway, these are the operations that I understand you want to perform:
1) REMOVE (OR DELETE) A FILE.
If you know the filename and you definitely want to delete it, whether it exists or not, do this:
OPEN "file" FOR OUTPUT AS #9
CLOSE #9
KILL "file"
The OPEN FOR OUTPUT makes it a zero-length-file, which exists for the KILL.
2) CREATE A NEW FILE.
If you definitely want to create this file as a new file, whether it already exists of not, and whether it already has data on it or not, do this:
OPEN "file" FOR OUTPUT AS #9
3) ADD LINES TO AN EXISTING FILE.
If you want to add lines to an existing file, whether or not the file already exists, do this:
OPEN "file" FOR APPEND AS #9
Except for the DELETE, you could probably use the OPEN FOR APPEND for all the other cases. I think that's what Z!re was trying to tell you.
In summary, Based on what you say you want to do, I don't think you need to make any decision regarding whether the file exists or not. File exist logic can get hairy, and the only good way to do it is to use assembler logic.
Hope that helps..... Regards..... Moneo
Hey Moneo
Hows you? Me doing great.
I have question and Sid6.7 told me you might be some help.
For a program I need to remove a file, create a new one, and add lines to the file.
But the adding thing is kinda blury, because first I need a check to see if the file is empty or already contains some text. If it does contain text I need to put the new text after the old one.
You think you can help me on this one?
grtz
Seb
**********************************************************
Hi Seb,
I got your above message on PM. I'm posting my reply here because other people have already posted stuff.
In your first post you said: "I need to create a new file... but if it exists... I want to add a new line..."
In your last post you also said: "it matters because the program is deleting a file and recreating it... for that reason I need."
Sid6.7 says I helped on the DEEBEE program to check for an existing file. I checked this program and there's no "file exist" logic there. I wrote a subroutine to "delete" a file by opening it for output and closing it, which makes it a zero-length-file.
Anyway, these are the operations that I understand you want to perform:
1) REMOVE (OR DELETE) A FILE.
If you know the filename and you definitely want to delete it, whether it exists or not, do this:
OPEN "file" FOR OUTPUT AS #9
CLOSE #9
KILL "file"
The OPEN FOR OUTPUT makes it a zero-length-file, which exists for the KILL.
2) CREATE A NEW FILE.
If you definitely want to create this file as a new file, whether it already exists of not, and whether it already has data on it or not, do this:
OPEN "file" FOR OUTPUT AS #9
3) ADD LINES TO AN EXISTING FILE.
If you want to add lines to an existing file, whether or not the file already exists, do this:
OPEN "file" FOR APPEND AS #9
Except for the DELETE, you could probably use the OPEN FOR APPEND for all the other cases. I think that's what Z!re was trying to tell you.
In summary, Based on what you say you want to do, I don't think you need to make any decision regarding whether the file exists or not. File exist logic can get hairy, and the only good way to do it is to use assembler logic.
Hope that helps..... Regards..... Moneo
- Seb McClouth
- Veteran
- Posts: 342
- Joined: Wed Nov 09, 2005 7:47 am
- Location: Inside the Matrix...
- Contact:
thx everybody...
Moneo you explaining did the trick. I've implented the code and it works just like I wanted it too.
grtz
Moneo you explaining did the trick. I've implented the code and it works just like I wanted it too.
grtz
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.