View Single Post
Old November 29th, 2005, 11:25 AM
fogofogo fogofogo is offline
Authorized User
Join Date: Nov 2005
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default File System Object question

Hello All,

I have a script that checks a database for records and saves each record set as an asp file. The script uses the "FileSystemObject" to do this and is run once a month, so I can create an archive. (I have been asked to do it this way for SEO reasons)

In my database there is a field for date, and this date is entered as dd/mm/yyyy. My question is if its possible to have the FileSystemObject create a folder for each month and save the asp files into it?

Heres what my code looks like:


Dim Connection, Recordset
Dim sSQL, sConnString
Dim sFSO
Dim sThisPage
Dim TempPath
Dim f

'declare SQL statement that will query the database
sSQL = "SELECT * FROM DeHavillandNews"

'define the connection string, specify database 
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ 
"Data Source=" & Server.MapPath("casinonewsxml.mdb") 

'create an ADO connection and recordset
Set connection = Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.Recordset")

'Open the connection to the database
connection.Open sConnString

'Open the recordset object, execute the SQL statement
recordset.Open sSQL, connection

'create an instance of the FileSystemObject
SET sFSO = Server.CreateObject("Scripting.FileSystemObject")

'Loop through all your records in the database
DO WHILE NOT recordset.EOF

'Map a path to you unique file name based on the id in the database
sThisPage = Server.Mappath("htmlpages/"& recordset("ItemID") &".asp")

'Check if the file exists already and delete it
IF sFSO.FileExists(TempPath) = TRUE THEN

'Create a new file with the same name and fill it with content
Set f = sFSO.CreateTextFile(sThisPage, true)
f.write "<p class='newshead'>"& vbcrlf
f.write recordset("Heading") & vbcrlf
f.write "</p><p class='newstext'>"& vbcrlf
f.write recordset("Contents") & vbcrlf
f.write "</p>"& vbcrlf

'Begin the loop

Thanks guys - I really appreciate any input or help.