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)
Above is the VB Script code, I need to write the same code in Java.Here, we are executing a cmd pgpnetshare -v filename I have tried like this
上面是VB脚本代码,我需要在Java中编写相同的代码。在这里,我们正在执行一个cmd pgpnetshare -v文件名我试过这样的
//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]);
}
}
}
I have tried upto running command of Pgpnetshare. Can some one help me on the remaining part of the code. I
我已经尝试过运行Pgpnetshare的命令了。有人可以帮助我完成代码的剩余部分。一世
1 个解决方案
#1
its not clear what pgpnetshare is... but maybe this class will help:
不清楚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;
}
});
}
}
Usage:
try{
Walker w = new Walker("C:\\some folder\\");
w.walk();
}catch(IOException e){
e.printStackTrace();
}
#1
its not clear what pgpnetshare is... but maybe this class will help:
不清楚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;
}
});
}
}
Usage:
try{
Walker w = new Walker("C:\\some folder\\");
w.walk();
}catch(IOException e){
e.printStackTrace();
}