JT>My "FileCopy" procedure is easier/simpler than using SHELL and requires
less
JT>memory; I was just wondering if some sort of copy command might ever be
add
JT>to the PB language.
Try this:
'============================================================================
' CopyFile - Copy a file to a new location and/or filename.
'
' Source$ = File to copy.
' Target$ = New location and filename. You MUST specify the filename,
' even if it remains the same as the source filename.
'
FUNCTION CopyFile(BYVAL Source$, BYVAL Target$) PUBLIC AS INTEGER
IF NOT Exist(Source$) THEN
EXIT FUNCTION ' source does not exist
END IF
IF MID$(Target$,2,1)=":" THEN
Drive$ = LEFT$(UCASE$(Target$), 1)
END IF
BuffSize = 32256 ' 63 sectors
IF Exist(Target$) THEN ' see if file exists on target
KILL Target$ ' kill target file to free space
END IF
Free??? = DiskFree(Drive$) ' get free space on target disk
SourceHandle = FREEFILE
OPEN "B", SourceHandle, Source$
IF Free??? < LOF(SourceHandle) THEN ' do we have enough space?
CLOSE SourceHandle ' not enough bytes on target
EXIT FUNCTION
END IF
TargetHandle = FREEFILE
OPEN "B", TargetHandle, Target$
WHILE NOT EOF(SourceHandle)
GET$ SourceHandle, BuffSize, Buff$ ' read buffer from source
PUT$ TargetHandle, Buff$ ' write it to target
WEND
CLOSE SourceHandle, TargetHandle
FUNCTION = -1 ' success
END FUNCTION
'============================================================================
' DiskFree - Return the amount of free bytes on the specified drive; if the
' drive is invalid then assume the current logged drive
'
' Drive$ = Drive letter to return amount of free space. A null string
' will return the default drive.
'
FUNCTION DiskFree(BYVAL Drive$) PUBLIC AS DWORD
LOCAL Drive
Drive = ASCII(Drive$) - 64
IF Drive < 0 THEN
Drive = 0
END IF
! push DS ; save DS for PowerBASIC
! mov AX, &H3600 ; function 36h, get drive info
! mov DX, Drive ; put requested drive in DX
! int &H21 ; call DOS
! cmp AX, &HFFFF ; does AX = -1?
! je DiskFreeDone ; yes, there was an error
! mul CX ; AX = AX * CX
! mul BX ; AX = AX * BX
! mov FUNCTION[0], AX ; return low part of dword
! mov FUNCTION[2], DX ; return high part of dword
DiskFreeDone:
! pop DS ; restore DS for PowerBASIC
END FUNCTION
--Dave
---
þ QMPro 1.53 þ Recursive (r‹-k–r-s‹v) adj. See "recursive."
--- QScan v1.065b
---------------
* Origin: Nitelog BBS Monterey CA (408) 655-1096 (1:216/303) (1:216/303)
|