TGC Codebase Backup



Generic File save as, save, and open commands by Three Score

20th Oct 2004 1:13
Summary

rem these fuinctions do basic file i/o rem use them as you please rem for the read_file you must ahve txt declared global rem made by free-space.myftp.org rem leave the last pareme



Description

rem these fuinctions do basic file i/o
rem use them as you please
rem for the read_file you must ahve txt declared global
rem made by free-space.myftp.org
rem leave the last paremeter on both of them blank if you do not want silent and want them to choose a file






function file_saveas(what$,name$)
if name$=""
ret:
print "so what do you want to save this file as"
input file$
if file exist(file$)=1
print "that file exist's already do you want to over write y/n"
input temp$
if temp$="y"
delete file file$
else
goto ret
endif
endif
print "saving file"
open to write 1,file$
write string 1,what$
cls
else
if file exist(name$)=1 then delete file name$
print "saving file"
if file exist(name$)=1 then delete file name$
open to write 1,name$
write string 1,what$
cls
endif
if file open(1)=1 then close file 1
print "done"
endfunction






function read_file(num,fname$)
if fname$=""
ret2:
print "what file do you want to open"
input flname$
if file exist(flname$)=0
print "file does not exist"
goto ret2
endif
open to read 2,flname$
for i=1 to num+1
read string 2,temp$
if i=num-1 then read string 2,txt$
next i
else
if file exist(fname$)=0
print "error file don't exist"
print "please report this to the maker of this program"
txt$="error the file was not found"
exitfunction
else
open to read 2,fname$
for i=1 to num+1
read string 2,temp$
if i=num-1 then read string 2,txt$
next i
endif
endif
if file open(2)=1 then close file 2
endfunction



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem these fuinctions do basic file i/o
rem use them as you please
rem for the read_file you must ahve txt declared global
rem made by free-space.myftp.org
rem leave the last paremeter on both of them blank if you do not want silent and want them to choose a file
rem accident 





function file_saveas(what$,name$)
if name$=""
ret:
print "so what do you want to save this file as"
input file$
if file exist(file$)=1
print "that file exist's already do you want to over write y/n"
input temp$
if temp$="y"
delete file file$
else
goto ret
endif
endif
print "saving file"
open to write 1,file$
write string 1,what$
cls
else
if file exist(name$)=1 then delete file name$
print "saving file"
if file exist(name$)=1 then delete file name$
open to write 1,name$
write string 1,what$
cls
endif
if file open(1)=1 then close file 1
print "done"
endfunction






function read_file(num,fname$)
if fname$=""
ret2:
print "what file do you want to open"
input flname$
if file exist(flname$)=0
print "file does not exist"
goto ret2
endif
open to read 2,flname$
for i=1 to num+1
read string 2,temp$
if i=num-1 then read string 2,txt$
next i
else
if file exist(fname$)=0
print "error file don't exist"
print "please report this to the maker of this program"
txt$="error the file was not found"
exitfunction
else
open to read 2,fname$
for i=1 to num+1
read string 2,temp$
if i=num-1 then read string 2,txt$
next i
endif
endif
if file open(2)=1 then close file 2
endfunction