Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: knats on April 04, 2004, 07:50:52 AM



Title: need help on file checking and creating...
Post by: knats 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?


Title: need help on file checking and creating...
Post by: na_th_an 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$"