如何通过JavaScript找到或不存在远程服务器目录

时间:2012-04-12 14:49:29

标签: javascript ant

我在我的Ant脚本中使用javascript来传递运行时网络远程文件夹值作为输入。传递该值后,我发现输入文件夹路径存在与否。但我无法做到这一点。 我的代码如下。

    <script language="javascript">
    <![CDATA[
        importPackage(javax.io);
        importPackage(javax.swing);
        importPackage(java.lang);
        var deployment_machine = project.getProperty("var2");
        var deployment_machine = deployment_machine.substring(2,deployment_machine.indexOf("$")-2);
        var optionPane = JOptionPane.showInputDialog( 'Deployment location for GatewayFW in ' + deployment_machine + '?', null );
        var path = require('optionPane');
        if (path.existsSync("/the/path")) {
                // ...
            }

        if(!fso.FolderExists(optionPane))
        {
        var optionPane = JOptionPane.showInputDialog( 'Deployment location for GatewayFW in ?', deployment_machine );
        }
        else
        {
        project.setProperty('deploy_loc',optionPane);
        }           
    ]]>
    </script>
</then>
<else>
    <echo message="File need to check:- ${patch.path}/${patch.name}/GatewayFW_patch.zip is not exist"/>
</else>

`

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

<script language="javascript"> <![CDATA[ importPackage(java.io); importPackage(javax.swing); importPackage(java.lang); var deployment_machine = project.getProperty("var2"); var deployment_machine = deployment_machine.substring(2,deployment_machine.indexOf("$")-2);
do { var optionPane = JOptionPane.showInputDialog( 'Deployment location for GatewayFW in ' + deployment_machine + '?', null );
var dir = new File(optionPane); } while(!dir.exists()); project.setProperty('deploy_loc',optionPane); ]]> </script>
这里我们必须将文件(“文件夹路径”)分配给一个javascript变量,如上面的var = dir = new File(“文件夹路径”); 然后我们可以通过路径执行任何操作。