![]() |
|
|
|||||||
| Petri.co.il is happy to award auglan the title of Most Valuable Member !!! |
| Register | Calendar |
Search |
Today's Posts |
Mark Forums Read |
| Notices |
|
|
Script for Adlib gamethis thread has 1 replies and has been viewed 433 times
|
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
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
|
||||||||||
|
||||||||||
|
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
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.. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |