Area: Quik_Bas Msg: #184 Date: 04-26-92 00:40 (Public) From: Rick Cooper To: Scott Wunsch Subject: More Questions again!
Hello Scott!
Thursday April 23 1992, Scott Wunsch writes to All:
SW> to find them all.
SW> 3) I would like to copy files by reading as many as possible into memory
SW> before writing them (like XCOPY does). If possible, I would like
SW> EMS/XMS support so I don't have to do that either.
SW> 4) Is there any way to determine if a program is being run from a batch
SW> file? If so, can you tell what batch file?
DECLARE FUNCTION GetHandle& (FileName$)
DECLARE SUB CloseHandle (Handle&)
DECLARE SUB GetSetTimeDate (Which%, Handle&, Time&, Date&)
'$INCLUDE: 'Qb.Bi'
DECLARE SUB fcopy (First$, Second$)
First$ = ""
Second$ = ""
FOR i = 1 TO LEN(COMMAND$)
IF MID$(COMMAND$, i, 1) <> " " THEN
First$ = First$ + MID$(COMMAND$, i, 1)
ELSE
i = i + 1
EXIT FOR
END IF
NEXT i
FOR j = i TO LEN(COMMAND$)
IF MID$(COMMAND$, j, 1) <> " " THEN
Second$ = Second$ + MID$(COMMAND$, j, 1)
ELSE
j = j + 1
EXIT FOR
END IF
NEXT j
CALL fcopy(First$, Second$)
SUB CloseHandle (Handle&)
'***************************************************************************
' This Function Closes the Handle Assigned by Dos... DO NOT try to use the
' QuickBasic Close Function... Must Be Closed By Dos Or The File Will
' Remain Open... Can Be Sticky
'***************************************************************************
DIM InRegs AS RegTypeX, OutRegs AS RegTypeX
InRegs.Ax = &H3E00
InRegs.Bx = Handle&
CALL InterruptX(&H21, InRegs, OutRegs)
END SUB
SUB fcopy (First$, Second$)
'====================================================================
'The Buffer Size Is Determined By Checking Availible String Space
'If The Availible Space Is <= File Size Or the Quick Basic Limitation
'On Strings Then The Largest Applicable buffer Is Used Resulting In
'The Fastest Possible Copy
'====================================================================
DIM buffer AS STRING
OPEN First$ FOR BINARY AS #1
OPEN Second$ FOR BINARY AS #2
place# = 0
famount# = FRE(buffer)
buffer = ""
maxrecord# = 32767
IF maxrecord# > famount# THEN maxrecord# = famount#
bestrecord# = LOF(1)
FOR i = 1 TO bestrecord#
min# = LOF(1) - place#
IF min# >= maxrecord# THEN 'Determine Best
length# = maxrecord# 'Buffer Length
buffer = SPACE$(length#) 'And Redimension
GET #1, , buffer 'Buffer Accordingly
PUT #2, , buffer 'And Increment The
place# = place# + length# 'Location Pointer
buffer = ""
ELSEIF min# <= maxrecord# THEN 'Can We Get The
length# = min# 'Rest Of The File
buffer = SPACE$(length#) 'All At Once?
GET #1, , buffer 'If So Do It
PUT #2, , buffer
place# = place# + length#
buffer = ""
ELSE
END IF
IF place# >= bestrecord# THEN EXIT FOR 'If We Are At The
NEXT i 'End Leave
CLOSE
'**************************************************************************
' Now, Thanks To Tom Handlin's Suggestion, We Rest The New File's Time
' And Date Stamp To The Old File's Time And Date
'**************************************************************************
handle1& = GetHandle&(First$)
Handle2& = GetHandle&(Second$)
CALL GetSetTimeDate(0, handle1&, Time&, Date&)
CALL GetSetTimeDate(1, Handle2&, Time&, Date&)
CALL CloseHandle(handle1&)
CALL CloseHandle(Handle2&)
END SUB
FUNCTION GetHandle& (FileName$)
'***************************************************************************
' This routine simply gets a Dos file handle to pass to the function
' which sets the time and date of the destination file. DO NOT attempt
' to pass a QuickBasic File Number. it must be assigned and recognized by
' Dos for the function to succed
'***************************************************************************
DIM InRegs AS RegTypeX, OutRegs AS RegTypeX
OpenFile$ = FileName$ + CHR$(0)
InRegs.Ax = (256 * &H3D) + &H0
InRegs.Ds = VARSEG(OpenFile$)
InRegs.Dx = SADD(OpenFile$)
CALL InterruptX(&H21, InRegs, OutRegs)
GetHandle& = OutRegs.Ax
END FUNCTION
SUB GetSetTimeDate (Which%, Handle&, Time&, Date&)
'***************************************************************************
' This is the function Which actually gets and sets a file's Date Time stamp.
' Notice the handle& variable... this is ABSOULTLY essential for this
' function to succeed. I won't go into the time/date field encoding
' here... I will, however, demonstrait these later in a function to set the
' time or date or both to what ever you wish.
'****************************************************************************
DIM InRegs AS RegTypeX, OutRegs AS RegTypeX
IF Which% <> 1 THEN
InRegs.Ax = (256 * &H57) + &H0
ELSE
InRegs.Ax = (256 * &H57) + &H1
InRegs.Cx = Time&
InRegs.Dx = Date&
END IF
InRegs.Bx = Handle&
CALL InterruptX(&H21, InRegs, OutRegs)
IF Which% <> 1 THEN
Time& = OutRegs.Cx
Date& = OutRegs.Dx
END IF
END SUB
Just got back from a rather.. obnoxious batchlor's party..
this is the copy function you requested... I have the dir
funtions later.
Rick
--- GoldED 2.40
* Origin: Just For The Heck Of It II -=(Fort Wayne In)=- (FidoNet 1:236/16)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET