Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Script for Adlib game

Script for Adlib game

this thread has 1 replies and has been viewed 433 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 9th August 2012, 21:06
McCordRM McCordRM is offline
Casual
Casual
 
 Join Date: Aug 2012
  6 month star
 Posts: 1
 Reputation: McCordRM is on a distinguished road (10)
Default Script for Adlib game

My friend's kid has a birthday coming up and he likes Adlibs- where you make new stories based on inputting different words each time.
I'm trying to figure out how to create a script to do this:


I have a directory called C:\Story
Inside the directory is an index.html file with the keyword ChangeMe scattered through-out it.

Another directory with images at C:\Story\images
Inside this directory are various images all named ChangeMeSomething.jpg.

And, of course, the C:\Story\css directory will just be copied to the new directory.

I need a script which will:
1. Ask the user to input a city name. (We'll call the answer $City)
2. Create a new directory called C:\$City.
3. Open each .HTML file in C:\Story and change every instance of ChangeMe to $City and save the new .HTML file in C:\$City with the same file name.
4. Create directory C:\$City\images and copy all pics in C:\Story\images to C:\$City\images with the new name $CitySomething.jpg
5. Copy C:\Story\css to C:\$City\css

Thanks in advance. I've never done anything like this and I'm have a terrible freakin' time figuring out how. I just thought it would be neat for the kid.
  #2  
Old 13th August 2012, 16:42
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,265
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (903)
Default Re: Script for Adlib game

maybe something like,
Code:
sourceFolder = "C:\Story"

sourceKeyword = "ChangeMe"

CityName = AskMe
destinationFolder = "C:\$" & CityName  'remove the $ sign if you don't like it.


DIM objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

' create new directory
If objFSO.FolderExists(destinationFolder) = False Then
   MakeDir(destinationFolder & "\images")
Else
   wscript.echo "A folder with that name already exists." _
       & vbNewLine & "Delete it or rename it first, then try again."
   CityName = AskMe   
End IF

' copy css files
objFSO.CopyFolder sourceFolder & "\css", destinationFolder & "\css"

' enum files in images subfoder, copy and rename to the new folder
Set objFolder = objFSO.GetFolder(sourceFolder & "\images")
Set colFiles = objFolder.Files
For Each objFile in colFiles
   ObjFSO.CopyFile objFile.path, destinationFolder & "\images\" _
     & Replace(objFile.Name, sourceKeyword, CityName,1,-1,1)
Next

' copy and edit index.html file
Set objFile = objFSO.OpenTextFile(sourceFolder & "\index.html", 1)
strText = objFile.ReadAll
objFile.Close
strText = Replace(strText, sourceKeyword, CityName, 1,-1,1)
Set objFile = objFSO.CreateTextFile(destinationFolder & "\index.html",true)
objFile.WriteLine strText
objFile.Close


function AskMe
   AskMe = Trim(inputbox(vbNewLine & vbNewLine _
       & vbNewLine & vbNewLine & vbNewLine _
       & "Enter the name of a city" _
       , "Name of city", sourceKeyword))
   'If it was typed strip off the leading $ sign
   If instr(AskMe, "$") = 1 Then AskMe = mid(AskMe,2)
   If IsEmpty(AskMe) Then wscript.quit
end function

Function MakeDir(strPath)
  Dim strParentPath
  With objFSO
    If Not .FolderExists(strPath) Then
      strParentPath = .GetParentFolderName(strPath)
      If Not .FolderExists(strParentPath) Then MakeDir strParentPath
      If Not .FolderExists(strPath) Then .CreateFolder strPath
    End If 
    MakeDir = .FolderExists(strPath)
  End With
End Function
Paste the code into a new Notepad file. Give the file an .vbs extension.
Start the script by dubbelclicking the vbs file.
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts

Last edited by Rems; 13th August 2012 at 19:34..
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Forum Game: What Photo is that? legendvpn12 Coffee Lounge and Introduction 4 1st February 2012 02:02
Problems running a game on VMware Kain VMware Virtualization 1 23rd August 2009 00:54
Running a game in VMWare YourGreatestMember VMware Virtualization 8 7th September 2008 17:54
VMware and compatibility with game Katerina VMware Virtualization 3 20th August 2008 17:24


All times are GMT +3. The time now is 00:59.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri