Create unique file name

C

CJA

Hi

I have a script that will compact an Access MDB and a copy to a new folder.
I would it to give each export a unique file name. I can do this with an
absolute file reference but I am struggling to create one using
'Server.MapPath'. Any ideas?

CJA
 
C

Chris Barber

An example would be useful - how are you creating the filepath and what exactly do you need to
achieve? Server.MapPath simply takes a relative url filepath and converts it to the filesystem based
path.

Chris.

Hi

I have a script that will compact an Access MDB and a copy to a new folder.
I would it to give each export a unique file name. I can do this with an
absolute file reference but I am struggling to create one using
'Server.MapPath'. Any ideas?

CJA
 
C

CJA

Hi

The current scrip is:

Dim objJetEngine


Set objJetEngine = Server.CreateObject("JRO.JetEngine")
objJetEngine.CompactDatabase _
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& Server.MapPath("../DB/Live.mdb") & ";",_
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& Server.MapPath("../Admin/Downloads/NewLive.mdb") & ";"

Set objJetEngine = Nothing


I would like to change so that I can put a date before the file name eg:

myfilename = Date() &"NewLive.mdb"
myfilename = Replace(myfilename, "/", "-")
 
C

Chris Barber

Try this (including the ISO date function ):

Dim pstrSourceFilePath
Dim pstrTargetFilePath

pstrSourceFilePath = Server.MapPath("../DB/Live.mdb")
pstrTargetFilePath = Server.MapPath("../Admin/Downloads/" & IsoDate(Now()) & "NewLive.mdb"

Dim objJetEngine

Set objJetEngine = Server.CreateObject("JRO.JetEngine")
objJetEngine.CompactDatabase _
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& pstrSourceFilePath & ";",_
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& pstrTargetFilePath & ";"

Set objJetEngine = Nothing

Function IsoDate(dteDate)
If IsDate(dteDate) = True Then
DIM dteDay, dteMonth, dteYear
dteDay = Day(dteDate)
dteMonth = Month(dteDate)
dteYear = Year(dteDate)
IsoDate = dteYear & _
"-" & Right(CStr(dteMonth + 100),2) & _
"-" & Right(CStr(dteDay + 100),2)
Else
IsoDate = Null
End If
End Function

Server.MapPath doesn't have to have a path that resolves - it merely changes the first part of *any*
path to take account of the location of the website root.

Chris.
Hi

The current scrip is:

Dim objJetEngine


Set objJetEngine = Server.CreateObject("JRO.JetEngine")
objJetEngine.CompactDatabase _
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& Server.MapPath("../DB/Live.mdb") & ";",_
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
& Server.MapPath("../Admin/Downloads/NewLive.mdb") & ";"

Set objJetEngine = Nothing


I would like to change so that I can put a date before the file name eg:

myfilename = Date() &"NewLive.mdb"
myfilename = Replace(myfilename, "/", "-")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top