home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
basic
/
library
/
pb
/
library5
/
disk.bas
< prev
next >
Wrap
BASIC Source File
|
1990-05-14
|
4KB
|
125 lines
$link "disk.obj" ' external object file.
' ----------------------------------------------------------------------------
declare function backup%(string,string) ' Copy Files
declare function curdrv%() ' Get current drive
declare function exist%(string) ' check for file attributes
declare function find1$(string,integer) ' Find First
declare function find2$() ' Find Next
declare function freespace&(string) ' return free space on a drive
declare function iam$() ' return the current programs pathname
declare function isdir$() ' get the current directory
declare function size&(string) ' return the size of a file (bytes)
declare sub chdrv(string) ' Change Drive
declare sub flush() ' Flush File Buffers
' ----------------------------------------------------------------------------
Function Dir$(mask$,attr%) ' function to return the directory
local a$,b$ ' in a string. mask$ is the search
' mask (i.e. "*.BAS") and attr% are
if mask$ = null$ then mask$ = "*.*" ' the file attributes to search for
a$ = find1$(mask$,attr%) ' 0 = normal files only
' 2 = normal + hidden files
if a$ = null$ then ' 4 = normal + system files
Dir$ = null$ '16 = volume label only
exit function ' Dir$ will return as a string
end if ' containing the matching files
' seperated by spaces.
b$ = a$
a$ = find2$
while a$ <> null$
b$ = b$ + " " + a$
a$ = find2$
wend
Dir$ = b$
End Function
' ----------------------------------------------------------------------------
Function DoBackup%(orig$,dest$) ' This function will backup files.
orig$ = ucase$(orig$) + chr$(0)
dest$ = ucase$(dest$) + chr$(0)
DoBackup% = backup%(orig$,dest$)
End Function
' ----------------------------------------------------------------------------
' Sample Program to demonstrate Function Iam$, IsDir$, Size& and Exist%
' ----------------------------------------------------------------------------
print
print "The current directory is: ";isdir$ ' test the function
print "The current program is: ";iam$
print
input "Enter a filename {no wildcards} for exist: ";filname$
a% = exist%(filname$)
if a% = -1 then
print "Doesn't Exist"
print "Size = ";size&(ucase$(filname$))
else
print "Exists = ";a%
print "Size = ";size&(ucase$(filname$))
end if
print
' ----------------------------------------------------------------------------
' Sample Program to Demonstrate DIR$, Curdrv%, Chdrv, Flush and Freespace&
' ----------------------------------------------------------------------------
cd$ = chr$(curdrv%)
print "The current drive is: ";cd$
print "There are ";freespace&(chr$(curdrv%));" bytes available on this drive."
input "Enter the drive to log: ";drv$
call chdrv(ucase$(drv$)) ' change drive
print "There are ";freespace&(chr$(curdrv%));" bytes available on this drive."
input "Enter the mask: ";msk$ ' enter the search string
cur$ = dir$(msk$,&h00) ' find normal files only
if cur$ <> null$ then ' print the result
cls
print cur$
print tally(cur$," ")+1;" Files."
else
print "No Files."
end if
call flush ' flush all file buffers.
' doesn't close files.
call chdrv(cd$)
' ----------------------------------------------------------------------------
' Sample Program to demonstrate Backup%
' ----------------------------------------------------------------------------
print
input "Enter Original File Name: ";source$
input "Enter Backup File Name: ";destin$
a% = dobackup%(ucase$(source$),ucase$(destin$))
if a% <> -1 then
select case a%
case = 1
print "Can't open original file."
case = 2
print "Can't open backup file."
case = 3
print "Disk Read Error."
case = 4
print "Disk write error."
case = 5
print "Disk full."
case = 6
print "Original file close error."
case = 7
print "Backup file close error."
case else
print "Unknown error."
end select
else
print "Successful Completion! "
end if
stop