Qbasicnews.com
July 03, 2020, 09:52:26 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: command request  (Read 2738 times)
dumbledore
Ancient Guru
****
Posts: 520



WWW
« on: April 29, 2005, 02:02:45 AM »

how about an exist command, like in batch files?  something like

if exist("c:\somefile.txt") then
  'open it & do stuff
else
  print "file not found!"
end if

would be pretty helpful, and it's pretty hard to get it to work without getting a runtime error with existing functions which can make it hard to debug...
Logged

ttp://m0n573r.afraid.org/
Quote from: "HexDude"
quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Z!re
*/-\*
*****
Posts: 4599


« Reply #1 on: April 29, 2005, 02:11:51 AM »

Code:
if DIR$("c:\somefile.txt") <> "" then
 'open it & do stuff
else
print "file not found!"
end if


To list all files based on a search:
Code:
filespec$ = "*.bas"
t$ = DIR$(filespec$)
Do until t$ = ""
  print t$
  t$ = DIR$
Loop
Logged
dumbledore
Ancient Guru
****
Posts: 520



WWW
« Reply #2 on: April 29, 2005, 02:15:38 AM »

lol, that'll work good, thanks
Logged

ttp://m0n573r.afraid.org/
Quote from: "HexDude"
quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #3 on: April 29, 2005, 02:25:31 AM »

From compiler's code:

Code:
'':::::
function hFileExists( byval filename as string ) as integer static
    dim f as integer

    f = freefile

if( open( filename, for input, as #f ) = 0 ) then
function = TRUE
close #f
else
function = FALSE
end if

end function
Logged

fsw
Guru
**
Posts: 251


« Reply #4 on: April 29, 2005, 12:06:23 PM »

If I open a file with the fb build-in command how can I obtain the file handle?
Maybe I missed something...

Thanks
Logged
dumbledore
Ancient Guru
****
Posts: 520



WWW
« Reply #5 on: April 29, 2005, 06:50:29 PM »

heh, another undocumented command  :roll:
lol we really need a official complete command reference
Logged

ttp://m0n573r.afraid.org/
Quote from: "HexDude"
quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #6 on: April 29, 2005, 07:30:18 PM »

Nope, every function that throws run time errors returns the error number, 0 meaning OK.

OPEN, CLOSE, GET and PUT can be used as functions since version 0.13 (it's in the changelog), so error handlers are not needed. Syntax sugars like LINE INPUT couldn't be converted, nor INPUT that is a statement and function also.. hail to M$.
Logged

dumbledore
Ancient Guru
****
Posts: 520



WWW
« Reply #7 on: May 01, 2005, 12:57:58 AM »

um v1c, it's good that you're providing a test version of .14, but how about systems other than windows? (aka linux)  :wink:
Logged

ttp://m0n573r.afraid.org/
Quote from: "HexDude"
quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #8 on: May 01, 2005, 01:20:25 PM »

The DOS and Linux versions can be cross-compiled, for both the runtime lib must to be first rebuilt.

Now for DOS you have just to "exchange" the Win32 GAS by the DOS one and do a "set OS=DOS" before make'ing.

With the Linux version it's more complex. First you have to use the makefile.linux, then the fbc.asm has to be hand edited to include the command-line processing needed in Linux (copy it from some asm generated by 0.13 in Linux, the lines between the entry-point "fb_???_entry:" and "call fb_moduleinit"); the asm files can now be copied to the Linux installation (???/src/compiler/obj/linux) and assembled. Just build the compiler and the new obj files will be used (if you didn't update the .bas sources after creating the obj's, that's it).
Logged

Moneo
Na_th_an
*****
Posts: 1971


« Reply #9 on: May 01, 2005, 04:23:01 PM »

Quote from: "v3cz0r"
From compiler's code:

Code:
'':::::
function hFileExists( byval filename as string ) as integer static
    dim f as integer

    f = freefile

if( open( filename, for input, as #f ) = 0 ) then
function = TRUE
close #f
else
function = FALSE
end if

end function

Be careful:

* If the file to be opened is a ZERO LENGTH FILE, you will get a TRUE, because it does exist. If you're reading the file, you will get an immediate EOF.

* If the filename is invalid because it contains invalid characters or a wildcard, you will get a FALSE. You may need to know the difference between "does not exist" and "invalid filename".

*****
Logged
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #10 on: May 01, 2005, 06:00:54 PM »

Quote from: "v3cz0r"
The DOS and Linux versions can be cross-compiled, for both the runtime lib must to be first rebuilt.

Now for DOS you have just to "exchange" the Win32 GAS by the DOS one and do a "set OS=DOS" before make'ing.


I've built the DOS fbc.exe from the Win32 one before (obviously... Smiley ) but I can't seem to make it work now.  Do I put the win32 as.exe into the bin\dos dir? And do I need to move the win32 ld.exe there too?
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #11 on: May 02, 2005, 01:18:33 AM »

It's the inverse, the djgpp's as.exe goes to the win32/bin, as the win32 version will only "see" that dir.

I've changed the sources so no Linux argc/argv is done on each module level, but at the rtlib init(). I added also to the Win32 ver the -target option, so paths and quirks like no-underscore and no-stdcall are set and no other bs is needed.. i will commit the changes when more tests were done..
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!