Page 2 of 2

Posted: Sun Oct 16, 2005 6:39 pm
by moneo
Nathan1993 wrote:no space? Actually, the file name and the recognition in the file system takes up space... so it DOES take up space, just very little...
Read my lips: "no space in the user's directory."
*****

sorry

Posted: Tue Oct 18, 2005 9:59 am
by cryptid
actually all i wanted to do is check for a file and then append to it
i know how it is done in Batch:
======================================
if exist "C:\myfile.txt" goto append
if exist "C:\WiNDOWS\myfile.txt" goto appendix

:append
Echo Hi this lineis being putin by cryptid>>C:\myfile.txt
exit

:append1
Echo hahahahahahahahahahahahahaha>>C:\WINDOWS\myfile.txt
exit
======================================
So now how i do the same in Qbasic

Posted: Tue Oct 18, 2005 1:58 pm
by {Nathan}
easy.

Code: Select all

SHELL "yourbatchfilegoeshere.bat"

Posted: Tue Oct 18, 2005 2:13 pm
by cryptid
Nathan1993 wrote:easy.

Code: Select all

SHELL "yourbatchfilegoeshere.bat"
well i know i can use shell but i want the program to be 100% Qbasic i dont want to generate batch files( i feel it is a bit messy) so can the same batch file be translated into QBasic i mean translate the above batch file to QB code

Posted: Tue Oct 18, 2005 4:48 pm
by {Nathan}

Code: Select all

OPEN "C:\myfile.txt" FOR APPEND AS #1
IF NOT LOF(1) = 0 THEN PRINT #1, "HI this is a LINE lol IM 1337! not"
CLOSE #1
OPEN "C:\windows\mespecial.txt" FOR APPEND AS #1
IF NOT LOF(1) = 0 THEN PRINT #1, "hEhEhEhE! im specialer than that 1337 guy!"
untested, but should work. been so long since I did anything with files...

Posted: Tue Oct 18, 2005 7:36 pm
by moneo
Nathan1993 wrote:

Code: Select all

OPEN "C:\myfile.txt" FOR APPEND AS #1
IF NOT LOF(1) = 0 THEN PRINT #1, "HI this is a LINE lol IM 1337! not"
CLOSE #1
OPEN "C:\windows\mespecial.txt" FOR APPEND AS #1
IF NOT LOF(1) = 0 THEN PRINT #1, "hEhEhEhE! im specialer than that 1337 guy!"
untested, but should work....
Excellent, Nath. I think that's what cryptid wants.
However, there is a little suble difference between how his batchfile works and your code. If either file was a zero-length-file, the batchfile would treat it as existing, and append a record. In your code, if either file was zero-length, your code would not append a record. I don't think he cares about zero-length-files, so your solution will work fine.


NOTE: You other guys may want to notice that the LOF function is not only for files opened as binary. The manual says: "When a file is opened in any mode, the LOF function returns the size of the file in bytes." I tried it and it works.
*****

Posted: Wed Oct 19, 2005 7:38 am
by matt
yeah, man, i've been meaning to ask you when this came up:

What kind of programs zero length files/is there a stanard practice for implimenting them (eg. .zlf or some shit like that?).

In otherwords: Is it common practice to generate .bmp/.txt/.mpeg(you know, standard file extention) zero length files?

or is it more like any unusual file extension/lack thereof...

Or is there a naming system (like 000.000 )?

matt

Posted: Wed Oct 19, 2005 8:05 am
by MystikShadows
To the best of my knowledge, the main reason was so that two processes, piped together (as linux can do it best) could listen for each other this way without needing to communicate with each other per se.

Program1 for example would perform it's task...once it was done it would create a zero length file just so that program 2 would know it was now time (by finding that file in that folder) to start performing it's task. for example. I remember hearing that reason quite often. Today you can do that with task handling...but back then, when these files were used, inter process communication either didn't exist or no one knew how to use them efficiently so they did this instead. but I think they didn't exist period back then. :-).

Posted: Wed Oct 19, 2005 10:38 am
by Antoni
In the ugly and powerless batch scripting language of DOS and W9x, zero length files were used by the more 1337 programmers to overcome the limitations of the language.
Zero length files made good flags. And I remember a way to separe a file name from its extension using a dummy file and REN...

I must add those files were duly erased before the .BAT file ended.

Posted: Wed Oct 19, 2005 12:41 pm
by matt
right, so it was more of a hack (unless you were using parallel processing) then a standard programing practice... Good to know I'm not fork anthing major up then...

matt

Posted: Wed Oct 19, 2005 2:18 pm
by moneo
Antoni wrote:In the ugly and powerless batch scripting language of DOS and W9x, zero length files were used by the more 1337 programmers to overcome the limitations of the language.
Zero length files made good flags. And I remember a way to separe a file name from its extension using a dummy file and REN...

I must add those files were duly erased before the .BAT file ended.
Antoni, I agree with most of what you say, but consider the following. ERRORLEVEL codes are the most common flags used for communicating between programs and batchfiles, although many programmers are not familiar with generating these errorlevel codes. For example, if you use a batchfile to compile your QuickBasic programs, you can do "IF ERRORLEVEL 1" after the BC (compiler) to test for any compile errors and avoid doing the LINK.

A batchfile can invoke a program and test for an ERRORLEVEL, but a subsecuent program cannot. So, if someone wrote a program that needed to communicate something like "got an error" to the next program, he could use a zero-length-file as a flag or switch.

Yes, these zero-level-files should be duly erased after being tested, but in many instances they are not, and appear in the user's directory.
*****