• <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
            數據加載中……

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

                  這段時間,公司要我整理一個有點歷史的產品代碼。由于項目歷史久,長期又缺少管理,產品中的項目有點亂,以至于一個DLL模塊配置的輸出路徑竟然有輸出成exe可執行模塊。存在這樣問題的項目有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

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

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

            久久综合综合久久97色| 香蕉久久夜色精品升级完成| 久久精品国产亚洲av水果派| 国内精品人妻无码久久久影院 | 国产精品99久久免费观看| 青青青国产成人久久111网站| 久久精品无码一区二区三区日韩 | 国内精品久久久久久中文字幕| 综合久久精品色| 狠狠综合久久综合中文88| 久久久久人妻精品一区二区三区| 久久精品国产亚洲5555| 午夜天堂精品久久久久| 国内精品人妻无码久久久影院导航 | 狠狠88综合久久久久综合网| 久久精品国产亚洲AV不卡| 久久A级毛片免费观看| 久久久久亚洲精品天堂| 影音先锋女人AV鲁色资源网久久 | 99久久免费国产特黄| 中文字幕乱码人妻无码久久| 要久久爱在线免费观看| 中文字幕久久精品 | 久久毛片免费看一区二区三区| 色综合久久天天综合| 欧美性猛交xxxx免费看久久久| 久久精品成人| 精品综合久久久久久888蜜芽| www性久久久com| 色妞色综合久久夜夜| 99999久久久久久亚洲| 免费精品久久久久久中文字幕 | 日批日出水久久亚洲精品tv| 久久亚洲精品成人av无码网站| 91亚洲国产成人久久精品| 久久青青草视频| 亚洲AV日韩精品久久久久久 | 国产成年无码久久久久毛片| 久久伊人影视| 亚洲伊人久久综合影院| 久久青青草原精品国产|