I use this : (found from the forum)
Maybe this be be updated of made better.
function csvtransform()
LOCAL hCsv, cLine, aLine, nI := 0,aFiles[ADIR("*.csv")]
ADIR("*.csv", aFiles)
nFile = msglist(aFiles )
cFile = aFiles[nFile]
cDbf = STRTRAN(lower(cFile), ".csv", ".dbf")
// Calculate the max field lengt
// Caution : If there are CDX-files, dbf ceation will faile !! erase them first of code it...
IF ( hCsv := fOpen( cFile , 16 ) ) > 0
HB_FReadLine( hCsv, @cLine, chr( 10 ) )
aHeader = strtoarr(cLine)
nlenarray = len(aHeader)
aFieldcount = array(nLenarray)
afill(aFieldcount,1)
nTester = 1
nTeller = 1
cdeli = MsgSelect( { ";",","} )
WHILE HB_FReadLine( hCsv, @cLine, chr( 10 ) ) == 0
oWnd:SetMsg( "Process data "+str(nTeller++)) // Show progress, but slows down on large files
if cDeli = ","
FOR I := 1 TO nLenarray
if I < nLenarray
cStr = subStr( cLine, 1, at( [,], cLine ) - 1 )
cStr = STRTRAN(cStr, '"', '')
else
cStr = STRTRAN(cLine, '"', '')
endif
nlengte = len(alltrim(cStr))
if aFieldcount[ I ] < nLengte
afieldcount[i] = nLengte
endif
cLine := subStr( cLine, at( [,], cLine ) + 1 )
//cLine := subStr( cLine, at( ["], cLine ) + 1 )
NEXT
else
FOR I := 1 TO nLenarray
if I < nLenarray
cStr = subStr( cLine, 1, at( [;], cLine ) - 1 )
cStr = STRTRAN(cStr, '"', '')
else
cStr = STRTRAN(cLine, '"', '')
endif
nlengte = len(cStr)
if aFieldcount[ I ] < nLengte
afieldcount[i] = nLengte
endif
cLine := subStr( cLine, at( [;], cLine ) + 1 )
//cLine := subStr( cLine, at( ["], cLine ) + 1 )
NEXT
endif
ENDDO
builddbf(aHeader,aFieldcount,cDbf)
fClose( hCsv )
ELSE
alert( "BAD LUCK" )
return
ENDIF
fClose( hCsv )
close all