Qbasicnews.com
March 31, 2020, 08:07:29 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: need help on file checking and creating...  (Read 1266 times)
knats
New Member

Posts: 3


« on: April 04, 2004, 07:50:52 AM »

Im currently working on a map making too that scrolls(I hope).
But I need help on how to make a program that checks for existance  if a file with a certain name.

example:

If a  filename "worldmap01.wld" already exists then name the file to be saved as "worldmap02.wld" and so on.

How would I go about in doing that?
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: April 04, 2004, 10:27:26 AM »

Writing from the top of my head:

Code:
template$="WLDMAP"

i%=0: DO
   idx$=LTRIM$(RTRIM$(STR$(i%)))
   IF LEN(idx$)=1 THEN idx$="0"+idx$
   filename$=template$+idx$+".MAP"
   f%=FREEFILE
   OPEN filename$ FOR BINARY AS #f%
   IF LOF(f%)=0 THEN
      ' File does not exist!
      CLOSE #f%
      KILL filename$
      EXIT DO
   ELSE
      ' File exists!
      CLOSE #f%
   END IF
   i% = i% +1 ' Next filename
LOOP

' First filename not used in variable "filename$"
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
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!