Help with FileSystem object

Results 1 to 2 of 2

Thread: Help with FileSystem object

  1. #1
    John Dvorak Guest

    Default Help with FileSystem object

    I have a form wizard that allows me to create a new website. What happens is this: You name the new site(no spaces or illegal characters obviously) and click submit. Then, the following script is called and creates a new site with that name:<BR><BR>&#060;%<BR>websitedirectory=request.f orm("websitedirectory")<BR><BR>set objFSO= CreateObject ("Scripting.FileSystemObject")<BR>objFSO.CreateFol der"D:htmlusersmydomainhtml\" & websitedirectory<BR><BR>set objFolder= objFSO.GetFolder("D:htmlusersmydomainhtmlsitetempl ate")<BR>objFolder.Copy "D:htmluserssitesimoncomhtml\" & websitedirectory <BR>%&#062;<BR>The site has been created in the &#060;%response.write("websitedirectory")%&#062 ; directory.<BR><BR><BR>The code simply takes a template folder that contains a default framework site and creates a copy of it. Then it renames the copied folder to the name that was specified in the form. <BR><BR>I need to take this one step farther though. The connection script to the database is contained within a file called "application.asp". And it looks like so:<BR><BR>StrConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:htmlusersmydomainhtmlsitetemplatecgi-binwebsite.mdb"<BR><BR>In order to get this script to point to the correct path(after the new folder has been created) I need to change the word "sitetemplate" to match the name of the newly created folder. <BR><BR>Any ideas on how I could do that? Or perhaps there may be another way to code the connection script so that it is not hard coded ...<BR><BR><BR>- Thanks!

  2. #2
    Join Date
    Dec 1969

    Default RE: Help with FileSystem object

    Lots of ways to do this, but I think I&#039d do it this way:<BR><BR>When you create the new Website, you do *NOT* copy one file. And that file is named (arbitrary...change as you wish) "WebsiteInclude.asp"<BR><BR>Then, for each new Website directory, you use FSO to create a file of that name and write into it something like this:<BR><BR>&#060;%<BR>Set FSO = Server.CreateObject("Scripting.FileSystemObject")< BR>Set webInc = FSO.CreateTextFile("D:htmluserssitesimoncomhtml\" _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;& websitedirectory &"WebsiteInclude.asp")<BR>webInc.WriteLine "&#060;" & "%"<BR>webInc.WriteLine "CONST webSiteLocation = """ & websitedirectory & """"<BR>webInc.WriteLine "%" & "&#062;"<BR>webInc.Close<BR>...<BR>%&#062;<BR><BR> Then, in the file where you need the DB connection, you do<BR><BR>&#060;!-- include file="WebsiteInclude.asp" --&#062;<BR><BR>at the top of the page and<BR><BR>StrConnect = "Driver={Microsoft Access Driver (*.mdb)}; " _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;& "DBQ=D:htmlusersmydomainhtml\" & webSiteLocation & "cgi-binwebsite.mdb"<BR><BR>and presto.<BR><BR>***********************<BR><BR>HAVI NG SAID ALL THAT...<BR><BR>Does it occur to you that doing<BR><BR>&#060;%<BR>curdir = Server.MapPath(".")<BR>%&#062;<BR><BR>will end up putting<BR><BR>"D:htmlusersmydomainhtml\" & websitedirectory<BR><BR>into the curdir variable? <BR><BR>or you could do just<BR><BR>StrConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("cgi-binwebsite.mdb")<BR><BR>and it should work!<BR><BR>Still, if you need several "constant for this particular site" values for your various ASP scripts, the include file trick should work well.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts