dos2unix 格式转换之VBScript脚本

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
---------------------------------------------------------------------------------

你可能感兴趣的:(unix,格式,格式转换,dos2unix,dosunix)