Hi,
I'm new here and to VBScript. I need to open a CSV file and store these data in the database. I already fail on opening the CSV, because FileExists returns FALSE and I have no idea how to find out the exact file position.
Here's the script I wrote so far:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Option Explicit
On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim strCsvFile
strCsvFile = Server.MapPath("test.csv")
'response.write(strCsvFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
' check existance
if (not objFSO.FileExists(strCsvFile)) then
response.write(strCsvFile & " does not exist")
response.end
end if
' open file
Set objFile = objFSO.OpenTextFile(strCsvFile, ForReading, false)
Dim strLine, arrLine, strSqlInsert
Dim strDate, strCustom, strPageViews, strClicks, fltCtr, fltEarnings, fltEpc, fltEcpm, fltQuality
Dim arrDate, arrCustom
'Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
response.write(strLine)
arrLine = Split(strLine, ",")
arrDate = Split(arrLine(0), "/", 3) ' 12/31/2008
strDate = arrDate(2) & "-" & arrDate(0) & "-" & arrDate(1) ' 2008-12-31
response.write(strDate)
'Loop
objFile.Close
response.write("finito")
%> The "test.csv" is in the same folder then the ASP script above. The message output is always "D:\Webs\cli142\affiliate_test\admin\xyz\test.csv does not exist". In the FTP program, I see this server path: "/webroot/affiliate_test/admin/xyz". Is "webroot" a virtual directory? I just want to open a file by a script that is in the same directory :(
Thanks in advance,
Chris