歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> Unix基礎知識 >> dos2unix格式轉換之VBScript腳本

dos2unix格式轉換之VBScript腳本

日期:2017/3/3 15:23:21   编辑:Unix基礎知識

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.cn/OS/unix/

Copyright © Linux教程網 All Rights Reserved