JCSetter.vbs(Java CLASSPATH Setter)

來源:互聯網
上載者:User

'JCSetter.vbs(Java CLASSPATH Setter)<br />'t0nsha<liaodunxia#gmail.com><br />'v1.0@2010/3/20 第一版<br />'v1.1@2010/4/4對未設定CLASSPATH環境變數的情況進行了修正.</p><p>Option Explicit<br />Public Const g_program = "JCSetter"<br />Public Const g_delimiter = ";"<br />Public Const g_classpath = "%CLASSPATH%"</p><p>'得到副檔名<br />Function GetFileExtensions(fileName)<br />GetFileExtensions = Mid(fileName, InStrRev(fileName, ".") + 1)<br />End Function</p><p>'遍曆指定檔案夾下的所有指定檔案<br />Function GetFilenames(currentFolderFullPath)<br />Dim fso, currentFolder, currentFileSet, currentFile, s<br />Set fso = CreateObject("Scripting.FileSystemObject")<br />Set currentFolder = fso.GetFolder(currentFolderFullPath)<br />Set currentFileSet = currentFolder.Files<br />For Each currentFile In currentFileSet<br />If LCase(GetFileExtensions(currentFile.Name)) = "jar" Then<br />s = s & currentFile.Path & g_delimiter<br />End If<br />Next<br />GetFilenames = s<br />End Function</p><p>'得到指令檔所在的目前的目錄<br />Function GetCurrentFolderFullPath<br />Dim fso<br />Set fso = CreateObject("Scripting.FileSystemObject")<br />GetCurrentFolderFullPath = fso.GetParentFolderName(WScript.ScriptFullName)<br />End Function</p><p>'遞迴遍曆目前的目錄下的所有檔案夾和子檔案夾<br />Function GetSubFolders(currentFolderFullPath)<br />Dim fso, currentFolder, subFolderSet, subFolder<br />Set fso = CreateObject("Scripting.FileSystemObject")<br />Set currentFolder = fso.GetFolder(currentFolderFullPath)<br />Set subFolderSet = currentFolder.SubFolders<br />For Each subFolder in subFolderSet<br />'MsgBox "subFolder.Path=" & subFolder.Path<br />GetSubFolders = subFolder.Path & g_delimiter & GetSubFolders(subFolder.Path) & GetSubFolders<br />Next<br />End Function</p><p>Dim arr, s, i, WshShell, cp<br />arr = Split(GetSubFolders(GetCurrentFolderFullPath), g_delimiter)<br />'arr最後一個元素為空白<br />For i = LBound(arr) To UBound(arr) - 1<br />s = s & GetFilenames(arr(i))<br />Next<br />'將搜尋到的jar包添加到CLASSPATH<br />Set WshShell = WScript.CreateObject("WScript.Shell")<br />'s = WshShell.ExpandEnvironmentStrings("%CLASSPATH%") & g_delimiter & s<br />cp = WshShell.ExpandEnvironmentStrings(g_classpath)<br />If cp = g_classpath Then<br />cp = "." & g_delimiter & s<br />Else<br />cp = "." & g_delimiter & s & g_delimiter & cp<br />End If<br />WshShell.Environment("User").Item("CLASSPATH") = cp<br />'MsgBox "[" & cp & "] has been added to CLASSPATH!"<br />MsgBox "The environment variable [CLASSPATH] includes:" & vbCrLf & vbCrLf & cp, vbOKOnly, g_program

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.