dos2unix格式轉換之VBScript指令碼

來源:互聯網
上載者:User

Unix軟體開發,一般情況下我們會在windows下使用工具進行開發測試,然後上傳到Unix下(測試),但是通常情況下工具儲存的是dos格式,上傳上去後往往會出現一些問題(如ClearCase下下來後都增加了換行,Oracle預存程序、Unix Shell不能運行等),於是我們就需要將格式轉換成unix格式再上傳。這個vbscript指令碼就是一個轉換工具。當然,我們也可以使用Eclipse,Notepad++等工具進行轉換。

dos2unix.vbs

This is a script for translating files from windows format to unix format.Maybe you always meet this situation that you create or edit your files on windows but can't work when upload to unix,  this tool can help you to solve this issue.

---------------------------------------------------------------------------------

on error resume next

Dim Fso

Set Fso = wscript.CreateObject("scripting.filesystemobject")

Dos2UnixFolder(".")

msgbox "Finished dos2unix!"

Function Dos2UnixFolder(ByVal path)

dim fd

set fd= fso.getfolder(path)

If fd.Files.Count > 0 Then

 For Each myf In fd.Files

  if right(lcase(myf.Name),6)<>".class" and right(lcase(myf.Name),4)<>".xml" then

   Dos2UnixFile(path&"/"&myf.Name)

  end if

 Next

End If

 If fd.subfolders.Count > 0 Then

 For Each myfd In fd.subfolders

  Dos2UnixFolder(path&"/"&myfd.Name)

 Next

End If

End Function

function Dos2UnixFile(filePath)

set f=fso.opentextfile(filePath)

s=replace(f.readall,vbcrlf,chr(10)) 'replace dos to unix format: vbcrlf=chr(13)chr(10)

f.close

set r=fso.opentextfile(filePath,2,true)

r.write s

end function

---------------------------------------------------------------------------------

本文出自 “小何貝貝的技術空間” 部落格,請務必保留此出處http://babyhe.blog.51cto.com/1104064/247256

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/OS/unix/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.