home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / file / file2-example.dba < prev   
Encoding:
Text File  |  2004-09-22  |  3.4 KB  |  159 lines

  1. rem File Functionality
  2.  
  3. rem Standard Setup Code for all examples
  4. set text font "arial" : set text size 16
  5. set text to bold : set text transparent
  6.  
  7. rem Launch external program and wait
  8. EXECUTE FILE "Exe.exe","","",1
  9.  
  10. rem Run file tests
  11. gosub _checklistfiles : gosub _waitkey
  12. gosub _checklistdrives : gosub _waitkey
  13. gosub _diranddrive : gosub _waitkey
  14. gosub _makefiles : gosub _waitkey
  15. gosub _deletefiles : gosub _waitkey
  16. gosub _sequentialwrite : gosub _waitkey
  17. gosub _sequentialread : gosub _waitkey
  18. gosub _readtoend : gosub _waitkey
  19. gosub _viewfiles : gosub _waitkey
  20. gosub _modifyafilebyte : gosub _waitkey
  21. gosub _showdata : gosub _waitkey
  22.  
  23. rem End program
  24. end
  25.  
  26. _checklistfiles:
  27.  cls : print "CHECKLIST FILES"
  28.  perform checklist for files
  29.  for f=1 to checklist quantity()
  30.  print "> ";checklist string$(f)
  31.  next f
  32. return
  33.  
  34. _checklistdrives:
  35.  cls : print "CHECKLIST DRIVES"
  36.  perform checklist for drives
  37.  for f=1 to checklist quantity()
  38.  print "> ";checklist string$(f)
  39.  next f
  40. return
  41.  
  42. _diranddrive:
  43.  cls : print "DRIVELIST AND DIR"
  44.  drivelist
  45.  dir
  46. return
  47.  
  48. _makefiles:
  49.  cls : print "MAKE FILES AND FOLDERS"
  50.  make directory "leedir"
  51.  set dir "leedir"
  52.  make file "leefile.txt"
  53.  copy file "leefile.txt","newfile.txt"
  54.  rename file "newfile.txt","renamed.txt"
  55.  move file "renamed.txt","moved.txt"
  56.  dir
  57.  set dir ".."
  58. return
  59.  
  60. _deletefiles:
  61.  cls : print "DELETE FILES AND FOLDERS"
  62.  set dir "leedir"
  63.  delete file "leefile.txt"
  64.  delete file "moved.txt"
  65.  dir
  66.  set dir ".."
  67.  delete directory "leedir"
  68. return
  69.  
  70. _sequentialwrite:
  71.  cls : print "WRITE SEQUENTIAL FILES"
  72.  if file exist("seq.txt") then delete file "seq.txt"
  73.  open to write 1,"seq.txt"
  74.  write file 1,1000
  75.  write byte 1,255
  76.  write word 1,65535
  77.  write long 1,2200000
  78.  write float 1,42.24
  79.  write string 1,"hello world"
  80.  write fileblock 1,"file.dat"
  81.  close file 1
  82.  print "file written"
  83. return
  84.  
  85. _sequentialread:
  86.  cls : print "READ SEQUENTIAL FILES"
  87.  open to read 1,"seq.txt"
  88.  read file 1,a : print a
  89.  read byte 1,a : print a
  90.  read word 1,a : print a
  91.  read long 1,a : print a
  92.  read float 1,a# : print a#
  93.  read string 1,a$ : print a$
  94.  read fileblock 1,"file2.dat"
  95.  close file 1
  96.  print "file read"
  97. return
  98.  
  99. _readtoend:
  100.  cls : print "READ EVERY BYTE OF A FILE"
  101.  open to read 1,"seq.txt"
  102.  if file open(1)=1
  103.   c=0
  104.   while file end(1)=0 and c<1000
  105.    read byte 1,A
  106.    print ">";A
  107.    inc c
  108.   endwhile
  109.   close file 1
  110.  endif
  111. return
  112.  
  113. _viewfiles:
  114.  cls : print "VIEW EACH FILE IN A FOLDER"
  115.  find first
  116.  while get file type()<>-1
  117.   print "Type:";get file type();
  118.   print " Name:";get file name$();
  119.   print " Date:";get file date$()
  120.   find next
  121.  endwhile
  122. return
  123.  
  124. _modifyafilebyte:
  125.  
  126. rem Read byte content of a file
  127. tbyte as BYTE
  128. tbyte=read byte from file("exe.exe",1000)
  129.  
  130. rem Write a transposed value back in same place
  131. write byte to file "exe.exe",1000,255-tbyte
  132.  
  133. rem Open file for sequential access
  134. open to read 1,"exe.exe"
  135. skip bytes 1,1000
  136. read byte 1,newbyte
  137. close file 1
  138. print newbyte
  139.  
  140. rem Restore file to normal
  141. write byte to file "exe.exe",1000,tbyte
  142.  
  143. return
  144.  
  145. _showdata:
  146.  cls : print "SHOW FILE DATA"
  147.  print "appname:";appname$()
  148.  print "windir:";windir$()
  149.  print "dir:";get dir$()
  150.  print "exist:";file exist("seq.txt")
  151.  print "pathexist:";path exist("leedir")
  152.  print "size:";file size("seq.txt")
  153. return
  154.  
  155. _waitkey:
  156.  print : print "Press Key"
  157.  wait key : sleep 500
  158. return
  159.