• <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)  編輯 收藏 引用 所屬分類: 天馬行空

            日本五月天婷久久网站| 色综合久久88色综合天天 | 久久久久久久久久久精品尤物| 99热热久久这里只有精品68| 精品久久人人做人人爽综合| 亚洲一区精品伊人久久伊人 | 亚洲国产成人乱码精品女人久久久不卡 | 久久丫忘忧草产品| 久久久久无码精品国产| 国产成人综合久久精品尤物| 久久天天躁狠狠躁夜夜不卡| 久久国产色AV免费观看| 国产视频久久| A狠狠久久蜜臀婷色中文网| 亚洲国产高清精品线久久 | 日韩AV毛片精品久久久| 国产成人无码久久久精品一| 久久久亚洲精品蜜桃臀| 久久91综合国产91久久精品| 精品国产青草久久久久福利| 国产成人久久精品二区三区| 国产人久久人人人人爽| 亚洲愉拍99热成人精品热久久| 精品无码人妻久久久久久| 国产精品久久久久久久| 伊人久久五月天| 久久亚洲高清综合| 青青草原1769久久免费播放| 777米奇久久最新地址| 亚洲级αV无码毛片久久精品| 色妞色综合久久夜夜| 久久久精品日本一区二区三区| 国产AV影片久久久久久| 青青草国产精品久久| 亚洲国产精品久久久久婷婷老年| 色欲综合久久中文字幕网| 亚洲狠狠婷婷综合久久蜜芽| 久久人人爽人人爽人人片AV不| 久久久久久伊人高潮影院| 一本色道久久综合狠狠躁| 无码精品久久久久久人妻中字 |