需要帮助将VBscript代码转换为java代码

时间:2015-05-04 02:34:43

标签: java vbscript

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脚本代码,我需要在Java中编写相同的代码。在这里,我们正在执行 cmd pgpnetshare -v filename  我试过这样的

    //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]);



        }
    }
}

我已经尝试过运行Pgpnetshare的命令了。有人可以帮助我完成代码的剩余部分。我

1 个答案:

答案 0 :(得分: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();
}