2012年7月4日星期三

regexp.vbs


'Email:leguanyuan@126.com
'Http://hi.baidu.com/correy
'本人喜欢看txt文件,又喜欢修改它,
'本人喜欢的工具是notepad2.exe,喜欢用它的alt+r的功能:移除空行。
'本文的功能是把所有的全部是空格组成的行变成空行。
'本脚本稍加修改,可能有别的用途,如:加密exe文件,dll文件,bmp文件,jpg文件等。
On Error Resume Next
notice = "made by correy"&Chr(13) & Chr(10)
notice = notice&"QQ:112426112"&Chr(13) & Chr(10)
notice = notice&"请选择你要操作的文件。"
wscript.echo notice
Set objFile = CreateObject( "SAFRCFileDlg.FileOpen" )
if err.number then
Set objDialog = CreateObject("UserAccounts.CommonDialog")   
bRet=objDialog.ShowOpen
if bRet then
    wscript.echo "你选择的文件是:"& objDialog.FileName &",确定请点击开始。"
    else
    wscript.echo "请选择文件,下面退出请重新开始"
    wscript.quit
end if
else
boolOpen = objFile.OpenFileOpenDlg
if boolopen then
    wscript.echo "你选择的文件是:"& objFile.FileName &",确定请点击开始。"
else
    wscript.echo "请选择文件,下面退出请重新开始"
    wscript.quit
end if
end if
Set FSO = CreateObject( "Scripting.FileSystemObject" )
Set txt = fso.OpenTextFile(objFile.FileName,1,True)
alltxt = txt.ReadAll
Set regEx = New RegExp
regEx.Pattern = " *\r\n"
regEx.IgnoreCase = True
regEx.Global = True
nospaceline = regEx.Replace(alltxt,chr(10)&chr(13))
wscript.echo "请选择选择你要保存的文件。点击确定开始。"
Set objsave = CreateObject( "SAFRCFileDlg.FileSave" )
if err.number then
wscript.echo "创建SAFRCFileDlg.FileSave对象失败,不能保存文件,点击退出。"
wscript.quit
end if
objsave.FileName = "*.*"
boolSave = objsave.OpenFileSaveDlg
if boolsave then
wscript.echo "你选择的文件是:"& objsave.FileName &",确定请点击开始。"
else
wscript.echo "请选择文件,下面退出请重新开始"
wscript.quit
end if
Set save = fso.OpenTextFile(objsave.FileName,2,True)
save.write nospaceline
wscript.echo "点击结束。"
'Set oDLG = CreateObject("MSComDlg.CommonDialog")
'oDLG.ShowSave

没有评论:

发表评论