从快捷链接提取路径-Windows Batch [英] Extract Path from shortcut link - windows batch
本文介绍了从快捷链接提取路径-Windows Batch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不使用vbscript的情况下从Windows批处理文件的快捷方式链接中提取路径?
How can I extract the path from a shortcut link in windows batch file without using vbscript?
推荐答案
You can do it with a wmic
query to win32_shortcutfile. Just make sure all your backslashes are backslash-escaped within %filename%
.
语法:
batfile shortcutfile.lnk
代码:
@echo off
setlocal
rem // ensure user supplied a filename with a .lnk extension
if /i "%~x1" neq ".lnk" (
echo usage: %~nx0 shortcut.lnk
goto :EOF
)
rem // set filename to the fully qualified path + filename
set "filename=%~f1"
rem // get target
for /f "delims=" %%I in (
'wmic path win32_shortcutfile where "name='%filename:\=\\%'" get target /value'
) do for /f "delims=" %%# in ("%%~I") do set "%%~#"
rem // preserve ampersands
setlocal enabledelayedexpansion
echo(!target!
这篇关于从快捷链接提取路径-Windows Batch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文