加入收藏 | 设为首页 | 会员中心 | 我要投稿 上海站长网 (https://www.021zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

dos2unix 格式转换之VBScript脚本

发布时间:2022-10-14 07:00:57 所属栏目:Unix 来源:互联网
导读: Unix软件开发unix媒体转换,一般情况下我们会在windows下使用工具进行开发测试,然后上传到Unix下(测试),但是通常情况下工具保存的是dos格式,上传上去后往往会出现一些问题(如ClearCa

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 fileson windows but can'twork 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

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

(编辑:上海站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章