窗" .LNK"快捷键和批处理不要混用 [英] windows ".lnk" shortcuts and batches don't mix

查看:149
本文介绍了窗" .LNK"快捷键和批处理不要混用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用来拖动包含.mp3s到批处理文件夹中的批处理文件。

I have a batch file which is used by dragging a folder containing .mp3s into the batch.

@echo off
cd %~dp0
setlocal enabledelayedexpansion enableextensions
set FLDR="%1"
if not defined FLDR ( echo Drag a folder to the batch to play its contents.
pause
goto:EOF )
for %%x in (%FLDR%\*.mp3) do set "MP3=!MP3! "%%x""
mp3player %MP3%
pause

它正常工作与实际的文件夹,但拖动快捷方式时,变量%FLDR%为C:\\链接位置\\ folder.lnk结束了,而不是实际的文件夹位置。
我不知道如何解决这个问题。

It works fine with actual folders, but when dragging shortcuts, the variable %FLDR% ends up as "c:\link location\folder.lnk" instead of the actual folder location. I have no idea how to get around this.

推荐答案

下面是一种使用一个小的混合VBS /批处理文件函数获取的对象。

Here is a way to get the target using a little hybrid VBS/Batch file function.

@echo off   
setlocal

Call :GetTarget "%~1" tgt 
echo %tgt%
pause
exit /b 


:GetTarget  
@echo off & setlocal
set gt=%temp%\_.vbs
echo set WshShell = WScript.CreateObject("WScript.Shell")>%gt%
echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>%gt%
echo wscript.Echo Lnk.TargetPath>>%gt%
set script=cscript //nologo %gt%
For /f "delims=" %%a in ( '%script% "%~1"' ) do set target=%%a
del %gt%
endlocal & set %~2=%target%
exit /b

这篇关于窗" .LNK"快捷键和批处理不要混用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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