2015-05-04 92 views
0
For Each objFile in ObjFiles 
      Dim Dir , text, filetocheck 

      filetocheck = """" & objFile & """" 
      Dir = """C:\Program Files\PGP Corporation\PGP Desktop""" 
      Dim WshShell, oExec 
      Set WshShell = WScript.CreateObject("WScript.Shell") 

      Set objExec = WshShell.Exec("cmd /K pgpnetshare -v " & filetocheck) 


      Set oShell = CreateObject("WScript.Shell") 
      Set oWmg = GetObject("winmgmts:") 
      strWndprs = "select * from Win32_Process where name='cmd.exe'" 
      Set objQResult = oWmg.Execquery(strWndprs) 

上面是VB Script代碼時需要幫助,我需要寫在Java.Here相同的代碼,我們正在執行一個CMD pgpnetshare -v名 我已經試過像這在翻譯VBScript代碼Java代碼

//For all files and folders in directory 
    for(int i=0; i<files.length; i++){ 
     //Check if directory 
     if(files[i].isDirectory()) 
      //Recursively call file list function on the new directory 
      VerifyFiles(files[i]); 
     else{ 
      //If not directory, print the file path 

      String path = "C:\\Program Files\\PGP Corporation\\PGP Desktop"; 

      Runtime rt = Runtime.getRuntime(); 
      rt.exec("cmd /K pgpnetshare -v"+ files[i]); 



     } 
    } 
} 

我已經嘗試upto運行Pgpnetshare命令。有人能幫我解決代碼的其餘部分嗎?我

+2

'rt.exec( 「CMD/K pgpnetshare -v」 + files [i]);' - 在-v之後應該有一個空格? –

+2

堆棧溢出不是一項免費的移植服務。也就是說,你可以通過指出代碼的實際問題來幫助自己,而不是簡單地在這裏傾銷一堆代碼。如果你不知道「上面的代碼是對還是錯」,你可以試着運行代碼*來看看會發生什麼。 – MarsAtomic

+0

@TagirValeev。感謝您的回覆,您可以在代碼的其餘部分使用我。 – user3493758

回答

0

它不清楚是...但也許這班將有助於什麼pgpnetshare:

import java.io.*; 
import java.nio.file.*; 
import java.nio.file.attribute.*; 

public class Walker{ 

    private Path _path; 

    public Walker(String p){ 
    this._path = Paths.get(p); 
    } 

    public void walk() throws IOException{ 
    Files.walkFileTree(this._path, new SimpleFileVisitor<Path>(){ 
     @Override 
     public FileVisitResult visitFile(Path f, BasicFileAttributes atr) throws IOException{ 
     Runtime.getRuntime().exec("cmd.exe /K \"c:\\program files\\PGP Corporation\\PGP Desktop\\pgpnetshare.exe\" -v \"" + f.toString() +"\""); 
     return FileVisitResult.CONTINUE; 
     } 
    }); 
    } 
} 

用法:

try{ 
    Walker w = new Walker("C:\\some folder\\"); 
    w.walk(); 
}catch(IOException e){ 
    e.printStackTrace(); 
}