获取批处理脚本中文件的绝对路径 [英] Get the absolute path of file in batch script

查看:330
本文介绍了获取批处理脚本中文件的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用批处理脚本来调用Java应用程序. Java应用程序将绝对文件路径作为参数.
我需要使用文件的相对路径或绝对路径作为参数来调用我的批处理脚本,然后将文件的绝对路径传递给Java执行.示例:

I am using batch script to invoke java application. Java app takes an absolute file path as an argument.
I need my batch script to be invoked with the relative or absolute path of the file as an argument and then to pass the absolute path of the file for java execution. Example:

从位置c:/folderA

myscript  folderB/file.txt  
myscript  c:/folderA/folderB/file.txt

在两种情况下,

应该都能获得完整的绝对路径c:/folderA/folderB/file.txt. 我该怎么办?
尽可能具体:在将ti的相对路径或绝对路径作为参数传递后,我只需要BATCH SCRIPT代码即可检索绝对文件路径字符串.当我用它调用Java应用程序时,它不是实际的部分.

should be able to get full absolute path c:/folderA/folderB/file.txt in both cases. How do I do that?
Just to be as much concrete as possible: I need only BATCH SCRIPT code to retrieve absolute file path string after passing either relative or absolute path to ti as an argument. Not the actual part when I invoke the java app with it.

推荐答案

您可以使用%~dpnx1.它扩展为第一个参数的驱动器,路径,名称和扩展名.不过,在将名称传递给另一个命令时,请不要忘记引用该名称.

You can use %~dpnx1. which expands to the drive, path, name and extension of the first argument. Don't forget to quote the name when passing it to another command, though.

这篇关于获取批处理脚本中文件的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆