Html 创建vbs/批处理文件以编辑文本文件并创建新文本文件

Html 创建vbs/批处理文件以编辑文本文件并创建新文本文件,html,batch-file,vbscript,cmd,Html,Batch File,Vbscript,Cmd,我对vbs不是很熟悉,但我对批处理文件很在行。我正在为我的工作地点创建一个简单的网站,作为销售和其他事项的公告。基本上,我有一个文本文件,这是一个新的销售项目的模板。我有一些事情想让我们办公室里那些不懂技术的人轻松一下。我正在寻找一个脚本来编辑主HTML文件,将新的.HTML文件添加到文件夹中,并使用带有选项提示(price、desc、dept等)的模板创建一个新的.HTML文件 我知道这听起来很难,但我希望这能很容易做到 基本上,我需要它: -提示更改标题、说明、价格和联系人-将此文件另存为i

我对vbs不是很熟悉,但我对批处理文件很在行。我正在为我的工作地点创建一个简单的网站,作为销售和其他事项的公告。基本上,我有一个文本文件,这是一个新的销售项目的模板。我有一些事情想让我们办公室里那些不懂技术的人轻松一下。我正在寻找一个脚本来编辑主HTML文件,将新的.HTML文件添加到文件夹中,并使用带有选项提示(price、desc、dept等)的模板创建一个新的.HTML文件

我知道这听起来很难,但我希望这能很容易做到

基本上,我需要它:

-提示更改标题、说明、价格和联系人-将此文件另存为item.html的标题 -将新的.html文件以日期、html位置和链接标题的格式添加到索引文件中

到目前为止,这里是我的index.html,只是为了让你了解这个网站有多简单

<HTML>
    <HEAD>

        <TITLE>Bulletin</TITLE>
    </HEAD>

<BODY>
    <CENTER><IMG SRC="logo.jpg">
    <CENTER><IMG SRC="bulletinboardbest.jpg" width=200 height=150></CENTER>
<H1>Bulletin Board</H1>
<font color="666666">To add an item please email <a href="mailto:email@email.com">email@email.com</a></font></CENTER>

<HR>



<!-Insert Items Below-!>

3/25/2013 - <A HREF="1999malibu.html">1999 Chevrolet Malibu For Sale</A>
<BR><BR>

3/28/2013 - <A HREF="orangescrewdriver.html">Orange Screw Driver For Sale</A>

<BR><BR><BR><BR><BR><BR>



</BODY>
</HTML>

布告栏
公告板
要添加项目,请发送电子邮件

3/25/2013 -

3/28/2013 -






项目网站模板

<HTML>
    <HEAD>
        <TITLE>Bulletin</TITLE>
    </HEAD>

<BODY>
    <CENTER><H1>Bulletin</H1></CENTER>






<!-Item Name-!>
    <H1>!!ITEM NAME HERE!!</H1> 





<!-Item Price-!>
    <H2><U>!!ITEM PRICE HERE!!</U></H2>





<!-Contact Info-!>
    <b><Font Color="Blue">!!CONTACT INFO HERE!!</b></font>
        <BR><BR><BR>






<!-Item Description-!>
    !!DESCRIPTION HERE!!



</BODY>
</HTML>

布告栏
布告栏
!!项目名称在这里!!
!!物品价格在这里!!
!!联系信息在这里!!



!!描述在这里!!
希望这不是太难。。。。正在尝试为非编码类型的人找出最简单的方法。

给你:

Option Explicit             
Const ForReading = 1                
Const ForWriting = 2                
Const ForAppending = 8              

Sub collectData()               
    Dim WshShell, sPath, sMain, sName, sDesc, sPrice, sContact          

    ' Save it to a folder on the Desktop            
    set WshShell = WScript.CreateObject("WScript.Shell")            
    sPath = WshShell.SpecialFolders("Desktop")          
    sPath = sPath & "\Scratch Files\"           

    sMain = "Bulletin.html"         

    ' Prompt for title, description, price, and contact         
    sName = getInput("Item Name")           
    sDesc = getInput("Item Description")            
    sPrice = getInput("Item Price")         
    sContact = getInput("Contact Information")          

    Call createFile(sPath, sName, sDesc, sPrice, sContact)          

    ' Add new .html file to index file in the format: date, <a href=html location>title for link</a>            
    Call appendFile(sPath, sMain, sName)            

    set WshShell = Nothing  
    Call Msgbox("Your item (" & sName & ") was added")
End Sub             

Function getInput(prompt)               
    getInput = inputbox(prompt,"Add New Item for Sale")         
End Function                

sub createFile(sPath, sName, sDesc, sPrice, sContact)               
    'Creates a new file, or appends to an existing file         
    Dim objFSO, objArgs(19), sTextFile, objFile, i          

    ' Create the File System Object         
    Set objFSO = CreateObject("Scripting.FileSystemObject")         

    ' Check if folder path exists; if not, create folder            
    If objFSO.FolderExists(sPath) then          
    Else            
        Call objFSO.CreateFolder(sPath)     
    End If          

    ' Save file as <title of item>.html         
    sTextFile = sPath & sName & ".html"             

    ' If file exists, open; else, create it         
    If objFSO.FileExists(sTextFile) Then            
        Set objFile = objFSO.OpenTextFile(sTextFile, ForAppending)      
    Else            
        Set objFile = objFSO.CreateTextFile(sTextFile)      
    End If          

    objArgs(1) = "<HTML>"           
    objArgs(2) = "    <HEAD>"           
    objArgs(3) = "        <TITLE>Bulletin</TITLE>"          
    objArgs(4) = "    </HEAD>"          
    objArgs(5) = ""         
    objArgs(6) = "<BODY>"           
    objArgs(7) = "    <CENTER><H1>Bulletin</H1></CENTER>"           
    objArgs(8) = "<!-Item Name-!>"          
    objArgs(9) = "    <H1>" & sName & "</H1> "          
    objArgs(10) = "<!-Item Price-!>"            
    objArgs(11) = "    <H2><U>" & sPrice & "</U></H2>"          
    objArgs(12) = "<!-Contact Info-!>"          
    objArgs(13) = "    <b><Font Color='Blue'>" & sContact & "</b></font>"           
    objArgs(14) = "        <BR /><BR /><BR />"          
    objArgs(15) = "<!-Item Description-!>"          
    objArgs(16) = "    " & sDesc            
    objArgs(17) = "</BODY>"         
    objArgs(18) = "</HTML>"         

    ' Write the details to the file         
    For i = 1 To UBound(objArgs)            
        objFile.WriteLine objArgs(i) & " "      
    Next            
    ' Append a newline character            
    objFile.WriteLine           

    ' Close the file            
    objFile.Close           

    set objFile = Nothing           
    set objFSO = Nothing            
End Sub             

Sub appendFile(sPath, sMain, sName)             
    Dim objFSO, objArgs(3), sTextFile, objFile, file, i, lBody          

    ' Create the File System Object         
    Set objFSO = CreateObject("Scripting.FileSystemObject")         

    ' Check if folder path exists; if not, create folder            
    If objFSO.FolderExists(sPath) then          
    Else            
        Call objFSO.CreateFolder(sPath)     
    End If          

    'Create filename            
    sTextFile = sPath & sMain           

    ' If file exists, open; else, create it         
    If objFSO.FileExists(sTextFile) Then            
        Set objFile = objFSO.OpenTextFile(sTextFile, ForReading)        
        file = Split(objFile.ReadAll(), vbCrLf)     
        objFile.Close()     
        Set objFile = objFSO.OpenTextFile(sTextFile, ForWriting)        
        For i = Lbound(file) to Ubound(file)        
            If inStr(file(i), "</BODY>") then   
                lBody = i
                Exit For
            Else    
                objFile.WriteLine(file(i))
            End If  
        Next        
    Else            
        Set objFile = objFSO.CreateTextFile(sTextFile)      
        file(1)=""      
    End If          

    objArgs(1) = Date() & " - <A HREF=""" & sName & ".html"">" & sName & " For Sale</A>"            
    objArgs(2) = "<BR /><BR />"         

    ' Write the details to the file         
    For i = 1 To UBound(objArgs)            
        objFile.WriteLine objArgs(i) & " "      
    Next            
    For i = lBody to Ubound(file)           
        objFile.WriteLine(file(i))      
    Next            

    ' Append a newline character            
    objFile.WriteLine           

    ' Close the file            
    objFile.Close           

    set objFile = Nothing           
    set objFSO = Nothing            
End Sub             

collectData()
选项显式
常数ForReading=1
写入常数=2
出现的常数=8
子集合数据()
黑暗的地狱,斯帕斯,斯曼,斯奈姆,斯达克,斯普里斯,斯康特
'将其保存到桌面上的文件夹中
设置WshShell=WScript.CreateObject(“WScript.Shell”)
sPath=WshShell.SpecialFolders(“桌面”)
sPath=sPath&“\Scratch文件”
sMain=“Bulletin.html”
'提示输入标题、说明、价格和联系人
sName=getInput(“项目名称”)
sDesc=getInput(“项目说明”)
sPrice=getInput(“项目价格”)
sContact=getInput(“联系信息”)
调用createFile(sPath、sName、sDesc、sPrice、SCOCONTACT)
'将新的.html文件以如下格式添加到索引文件:date,
调用appendFile(sPath、sMain、sName)
设置WshShell=Nothing
调用Msgbox(“添加了您的项目(&sName&”)
端接头
函数getInput(提示)
getInput=inputbox(提示“添加新的待售商品”)
端函数
子创建文件(sPath、sName、sDesc、sPrice、SCOCONTACT)
'创建新文件,或附加到现有文件
Dim objFSO,objArgs(19),sTextFile,objFile,i
'创建文件系统对象
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
'检查文件夹路径是否存在;如果不是,请创建文件夹
如果objFSO.FolderExists(sPath),则
其他的
调用objFSO.CreateFolder(sPath)
如果结束
'将文件另存为.html
sTextFile=sPath&sName&“.html”
'如果文件存在,请打开;否则,创建它
如果存在objFSO.files(sTextFile),则
设置objFile=objFSO.OpenTextFile(sTextFile,用于显示)
其他的
设置objFile=objFSO.CreateTextFile(sTextFile)
如果结束
objArgs(1)=“
objArgs(2)=“
objArgs(3)=“公告”
objArgs(4)=“
objArgs(5)=“
objArgs(6)=“
objArgs(7)=“公告”
objArgs(8)=“
objArgs(9)=“陷阱(&sName&”
objArgs(10)=“
objArgs(11)=&sPrice&“
objArgs(12)=“
objArgs(13)=“与接触”
objArgs(14)=“



” objArgs(15)=“ objArgs(16)=&sDesc objArgs(17)=“ objArgs(18)=“ '将详细信息写入文件 对于i=1至UBound(objArgs) objFile.WriteLine objArgs(i)和“” 下一个 '追加换行符 objFile.WriteLine '关闭文件 objFile.Close 设置objFile=Nothing 设置objFSO=Nothing 端接头 子附录文件(sPath、sMain、sName) Dim objFSO、objArgs(3)、sTextFile、objFile、file、i、lBody '创建文件系统对象 设置objFSO=CreateObject(“Scripting.FileSystemObject”) '检查文件夹路径是否存在;如果不是,请创建文件夹 如果objFSO.FolderExists(sPath),则 其他的 调用objFSO.CreateFolder(sPath) 如果结束 '创建文件名 sTextFile=sPath&sMain '如果文件存在,请打开;否则,创建它 如果存在objFSO.files(sTextFile),则 设置objFile=objFSO.OpenTextFile(sTextFile,ForReading) file=Split(objFile.ReadAll(),vbCrLf) objFile.Close() 设置objFile=objFSO.OpenTextFile(sTextFile,用于写入) 对于i=Lbound(文件)到Ubound(文件) 如果指令(文件(i),“”),则 lBody=i 退出 其他的 objFile.WriteLine(文件(i)) 如果结束 下一个 其他的 设置objFile=objFSO.CreateTextFile(sTextFile) 文件(1)=“” 如果结束 objArgs(1)=日期()&“-” objArgs(2)=“