home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY5 / DISK.ZIP / DISK.BAS next >
BASIC Source File  |  1990-05-15  |  4KB  |  125 lines

  1. $link "disk.obj"            ' external object file.
  2. ' ----------------------------------------------------------------------------
  3. declare function backup%(string,string) ' Copy Files
  4. declare function curdrv%()        ' Get current drive
  5. declare function exist%(string)        ' check for file attributes
  6. declare function find1$(string,integer)    ' Find First
  7. declare function find2$()        ' Find Next
  8. declare function freespace&(string)    ' return free space on a drive
  9. declare function iam$()            ' return the current programs pathname
  10. declare function isdir$()        ' get the current directory
  11. declare function size&(string)        ' return the size of a file (bytes)
  12. declare sub chdrv(string)        ' Change Drive
  13. declare sub flush()            ' Flush File Buffers
  14. ' ----------------------------------------------------------------------------
  15. Function Dir$(mask$,attr%)        ' function to return the directory
  16.   local a$,b$                ' in a string.  mask$ is the search
  17.                     ' mask (i.e. "*.BAS") and attr% are
  18.   if mask$ = null$ then mask$ = "*.*"    ' the file attributes to search for
  19.   a$ = find1$(mask$,attr%)              ' 0 = normal files only
  20.                          ' 2 = normal + hidden files
  21.   if a$ = null$ then                 ' 4 = normal + system files
  22.     Dir$ = null$                 '16 = volume label only
  23.     exit function            ' Dir$ will return as a string
  24.   end if                ' containing the matching files
  25.                     ' seperated by spaces.
  26.   b$ = a$
  27.  
  28.   a$ = find2$
  29.  
  30.   while a$ <> null$
  31.     b$ = b$ + " " + a$
  32.     a$ = find2$
  33.   wend
  34.  
  35.   Dir$ = b$
  36.  
  37. End Function
  38. ' ----------------------------------------------------------------------------
  39. Function DoBackup%(orig$,dest$)    ' This function will backup files.
  40.  
  41.   orig$ = ucase$(orig$) + chr$(0)
  42.   dest$ = ucase$(dest$) + chr$(0)
  43.  
  44.   DoBackup% = backup%(orig$,dest$)
  45.  
  46. End Function
  47. ' ----------------------------------------------------------------------------
  48. ' Sample Program to demonstrate Function Iam$, IsDir$, Size& and Exist%
  49. ' ----------------------------------------------------------------------------
  50.  
  51. print
  52. print "The current directory is: ";isdir$    ' test the function
  53. print "The current program is: ";iam$
  54. print
  55. input "Enter a filename {no wildcards} for exist: ";filname$
  56. a% = exist%(filname$)
  57. if a% = -1 then
  58.   print "Doesn't Exist"
  59.   print "Size   = ";size&(ucase$(filname$))
  60. else
  61.   print "Exists = ";a%
  62.   print "Size   = ";size&(ucase$(filname$))
  63. end if
  64.  
  65. print
  66.  
  67. ' ----------------------------------------------------------------------------
  68. ' Sample Program to Demonstrate DIR$, Curdrv%, Chdrv, Flush and Freespace&
  69. ' ----------------------------------------------------------------------------
  70.  
  71. cd$ = chr$(curdrv%)
  72. print "The current drive is:   ";cd$
  73. print "There are ";freespace&(chr$(curdrv%));" bytes available on this drive."
  74. input "Enter the drive to log: ";drv$
  75. call chdrv(ucase$(drv$))        ' change drive
  76. print "There are ";freespace&(chr$(curdrv%));" bytes available on this drive."
  77.  
  78. input "Enter the mask: ";msk$        ' enter the search string
  79. cur$ = dir$(msk$,&h00)            ' find normal files only
  80. if cur$ <> null$ then            ' print the result
  81.   cls
  82.   print cur$
  83.   print tally(cur$," ")+1;" Files."
  84. else
  85.   print "No Files."
  86. end if
  87.  
  88. call flush                ' flush all file buffers.
  89.                     ' doesn't close files.
  90. call chdrv(cd$)
  91. ' ----------------------------------------------------------------------------
  92. ' Sample Program to demonstrate Backup%
  93. ' ----------------------------------------------------------------------------
  94. print
  95. input "Enter Original File Name: ";source$
  96. input "Enter Backup File Name:   ";destin$
  97.  
  98. a% = dobackup%(ucase$(source$),ucase$(destin$))
  99.  
  100. if a% <> -1 then
  101.   select case a%
  102.     case = 1
  103.       print "Can't open original file."
  104.     case = 2
  105.       print "Can't open backup file."
  106.     case = 3
  107.       print "Disk Read Error."
  108.     case = 4
  109.       print "Disk write error."
  110.     case = 5
  111.       print "Disk full."
  112.     case = 6
  113.       print "Original file close error."
  114.     case = 7
  115.       print "Backup file close error."
  116.     case else
  117.       print "Unknown error."
  118.   end select
  119. else
  120.   print "Successful Completion! "
  121. end if
  122.  
  123. stop
  124.  
  125.