** tcFileName - File to be split into the specified size in KB.
** tcSplitSize - SplitSize in KB for the file.
#DEFINE _CRLF chr(13) + chr(10)
#DEFINE _COPYCMD "COPY "
#DEFINE _WIN95 'Windows 4.00'
#DEFINE _WINNT 'Windows NT'
parameters tcfilename, tnSplitSizeKB
local lnFileHandle, lnFileSize, lnSplitSize, lnSplitFileHandle, ;
lnSplitCnt, lnMaxSplits, lnTempCnt, lcTempFileName, lcSafety, ;
lnReadSize, lcCopyCmd, lcSplitFileName, lcTempStr, lcPrvStr, ;
lnRestSize, lnCopyCnt
if parameters() < 2 OR TYPE('tcfilename') <> 'C' OR TYPE('tnSplitSizeKB') <> 'N'
WAIT WINDOW "DO Split WITH , " TIME 2.0
RETURN(-1)
endif
if len(tcFileName) > 75
WAIT WINDOW "Input file name too big for creating the batch command." + ;
_CRLF + "Please give a smaller file name. Prefarably 30 characters."
TIME 2.0
RETURN(-1)
endif
lnFileHandle = fopen(tcFileName)
if lnFileHandle < 0
WAIT WINDOW "Unable to open input file for processing." TIME 2.0
RETURN(-1)
endif
** find size of file
lnFileSize = fseek(lnFileHandle, 0, 2)
* goto beginning of file
= fseek(lnFileHandle, 0, 0)
** determine split size in bytes.
lnSplitSize = (tnSplitSizeKB *1024)
if (lnSplitSize > lnFileSize)
WAIT WINDOW "Invalid split size specified for processing." TIME 2.0
RETURN(-1)
endif
** determine maximum splits required
lnMaxSplits = CEILING(lnFileSize/lnSplitSize)
lnReadSize = 0
lnCopyCnt = 1
lnRestSize = lnFileSize
lcCopyCmd = ""
lcTempStr = ""
for lnSplitCnt = 1 to lnMaxSplits
lcSplitFileName = STUFF(tcFileName, AT('.', tcFileName), 0, ALLT(STR(lnSplitCnt)))
lnSplitFileHandle = fcreate(lcSplitFileName)
if lnSplitFileHandle < 0
WAIT WINDOW "Unable to create split file #" + ALLT(STR(lnSplitCnt)) + "." TIME 2.0
** Delete all previous split files created.
lcSafety = SET("SAFETY")
SET SAFETY OFF
for lnTempCnt = 1 to (lnSplitCnt - 1)
lcTempFileName = STUFF(tcFileName, AT('.', tcFileName), 0, ;
ALLT(STR(lnSplitCnt)))
DELETE FILE &lcTempFileName
endfor
SET SAFETY &lcSafety
RETURN(-1)
endif
lnReadSize = iif((lnRestSize > lnSplitSize), lnSplitSize, lnRestSize)
lnRestSize = (lnRestSize - lnSplitSize)
= fwrite(lnSplitFileHandle, fread(lnFileHandle, lnReadSize))
= fclose(lnSplitFileHandle)
lcTempStr = '"' + lcSplitFileName + '"/B'
if lnSplitCnt = 1
lcCopyCmd = _COPYCMD + lcTempStr + ' "' + tcFileName + '"/B' +
IIF(AT(_WINNT, OS()) > 0, ' 1>NUL 2>NUL', '')
else
lcCopyCmd = lcCopyCmd + _CRLF + _COPYCMD + '"' + tcFileName + ;
'"/B+' + lcTempStr + ;
' "' + tcFileName + '"/B' + ;
IIF(AT(_WINNT, OS()) > 0, ' 1>NUL 2>NUL', '')
endif
endfor
= fclose(lnFileHandle)
lcCopyCmd = "@ECHO OFF" + _CRLF + "ECHO Combining files..." + _CRLF + lcCopyCmd
_CLIPTEXT = lcCopyCmd
lnBatHandle = fcreate(STUFF(tcFileName, AT('.', tcFileName) + 1, ;
LEN(tcFileName) - AT('.', tcFileName), 'BAT'))
if lnBatHandle < 0
WAIT WINDOW "Unable to create batch file for combining the splitted files." + ;
_CRLF + "Paste the batch command from the clipboard." TIME 2.0
RETURN(-1)
endif
= FPUTS(lnBatHandle, lcCopyCmd)
= FCLOSE(lnBatHandle)
RETURN(0)
This page was last updated on May 01, 2006 04:28 PM.