• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 64, 文章 - 11, 評論 - 12, 引用 - 0
            數(shù)據(jù)加載中……

            由正則表達式"\."引出的問題,而談及DOS文件格式

                  這段時間,公司要我整理一個有點歷史的產(chǎn)品代碼。由于項目歷史久,長期又缺少管理,產(chǎn)品中的項目有點亂,以至于一個DLL模塊配置的輸出路徑竟然有輸出成exe可執(zhí)行模塊。存在這樣問題的項目有30個左右,而且每個項目要改4個地方,因為有4種生成版本。如果手工去改的話實在很枯燥,但我們是程序員。所以就用代碼了。
             1' 更改所有資源的輸出路徑
             2
             3' get folder path
             4scriptName = wscript.scriptfullname
             5scriptPath = Left(scriptName, instrRev(scriptName, "\"))
             6scriptPath = Left(scriptPath, Len(scriptPath) -1)
             7scriptPath = Left(scriptPath, instrRev(scriptPath,"\"))
             8folderPath = scriptPath & "Loc\"
             9
            10' create filesystemobject activex object
            11Set fso = CreateObject("Scripting.FileSystemObject")
            12Set fol = fso.GetFolder(folderPath)
            13
            14' visit each file which in the folder
            15fileshortName = ""
            16Set fileArr = fol.Files
            17For each fil in fileArr
            18    fileName = fil.name
            19    If LCase(Right(fileName, 7)) = ".vcproj" Then
            20        fileshortName = Left(fileName,Len(fileName) - 7)
            21        If LCase(Right(fileshortName, 4)) <> "_enu" Then
            22            modifyResource fil.path,status
            23            If status =False Then
            24                errlist = errlist &  fil.Path & vbCr
            25            End If
            26        End If
            27    End If
            28Next
            29
            30' Tip when complete the work
            31If Len(errlist) > 0 Then
            32    MsgBox errlist & "Can not modify"
            33Else
            34    MsgBox "modify successfully"
            35End If
            36
            37' modify the resource project setting.
            38Function modifyResource(filePath,status)
            39On Error Resume Next
            40
            41    resLanguage = UCase(Right(fileshortName, 3))
            42    
            43    ' Read Content
            44    Set fRead = fso.opentextfile(filePath, 1)
            45    fContent = fRead.readAll
            46    fRead.close
            47    
            48    ' Replace each output file
            49    changed = False
            50    Set regEx = New RegExp
            51    regEx.pattern = "\bOutputFile=.+"
            52    regEx.Global = True
            53    Set matches = regEx.Execute(fContent)
            54    Set childReg = New RegExp
            55    For Each match in matches    
            56        If LCase(Right(match.Value, 9)) <> "\loc.dll""" Then            
            57            tmpValue = match.Value
            58            childReg.pattern = tmpValue
            59            If instrRev(tmpValue, "\")>0 Then            
            60                tmpValue = Left(tmpValue, instrRev(tmpvalue, "\"))
            61            ElseIf instrRev(tmpValue,"/"> 0 Then
            62                tmpValue = Left(tmpValue,instrRev(tmpValue,"/"))
            63            End If
            64            tmpValue = tmpValue & resLanguage & "\loc.dll"""
            65            childMatches = childReg.Execute(fContent)
            66            ' fContent = childReg.Replace(fContent, tmpValue)
            67            fContent = Replace(fContent, match.Value, tmpValue)
            68            changed = True
            69        End If
            70    Next    
            71
            72    ' write back
            73    If changed=True Then
            74        Set fWrite = fso.opentextfile(filePath, 2, False)
            75        fWrite.Write fContent
            76        fWrite.close
            77    End If
            78    ' clear error
            79    If Not err.number = 0 Then
            80        err.clear
            81        status = False
            82    Else
            83        status = True
            84    End If
            85End Function

            運行結(jié)果符合我們的要求。
               用ultraEdit打開文件時,會提示是否要轉(zhuǎn)換成DOS文件格式,但在轉(zhuǎn)換前用ultraEdit打開不會出現(xiàn)這種問題。問題出在哪兒呢?這還得從DOS文件與非DOS文件格式的區(qū)別分析,這兩種文件的差別就是一些控制符不同,如DOS是用\r\n來換行,而Unix是用\n來換行。有了這個分析,就知道問題出在哪了。原因是正則表達式
            regEx.pattern = "\bOutputFile=.+"這個表達式把后面的"\r"也匹配進去了,而后來隨著替換字符串時而消失了。所以上面的正則應(yīng)寫成regEx.pattern = "\bOutputFile=.+"""。改好之后運行,再用ultraEdit打開不會出現(xiàn)這個提示了。

            posted on 2009-04-28 13:48 Robertxiao 閱讀(359) 評論(0)  編輯 收藏 引用 所屬分類: 天馬行空

            欧美麻豆久久久久久中文| 久久久久亚洲AV成人片| 久久精品亚洲精品国产欧美| 国内精品久久久久久久久| 久久精品无码一区二区三区免费 | 无码人妻少妇久久中文字幕蜜桃| 久久精品国产99国产精品亚洲| 77777亚洲午夜久久多喷| 97久久精品人人澡人人爽| 久久天天婷婷五月俺也去| 国内精品久久人妻互换| 99精品国产免费久久久久久下载| 久久久久久a亚洲欧洲aⅴ| 亚洲天堂久久久| 激情综合色综合久久综合| 久久精品国产亚洲AV麻豆网站| 久久亚洲电影| 色综合久久中文综合网| 无码国产69精品久久久久网站| 国内精品久久久久久久久| 91精品国产综合久久婷婷| 精品多毛少妇人妻AV免费久久| 亚洲成人精品久久| 国产精品久久网| 午夜不卡久久精品无码免费| 久久综合久久综合亚洲| 精品免费久久久久国产一区 | 日本五月天婷久久网站| 精品无码人妻久久久久久| 久久综合久久综合久久| 久久se精品一区二区| 久久精品这里热有精品| 国产亚洲欧美成人久久片 | 欧美喷潮久久久XXXXx| 久久亚洲AV无码精品色午夜麻豆| 欧美国产成人久久精品| 青青青青久久精品国产h久久精品五福影院1421 | 精品一二三区久久aaa片| 午夜视频久久久久一区| 亚洲国产精品成人久久蜜臀 | 久久国产热这里只有精品|