2013-10-29 1 views
2

.mp3s가 들어있는 폴더를 배치로 끌어서 사용하는 배치 파일이 있습니다.windows ".lnk"바로 가기와 배치가 혼합되지 않음

@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"로 끝나는 대신 실제 폴더 위치. 이 문제를 해결하는 방법을 모릅니다.

+0

'lnk' 파일을 배치하여 액세스 할 수 없습니다. 폴더 링크를 시작하면 탐색기 창이 열립니다. – Endoro

답변

8

여기에 약간의 하이브리드 VBS/배치 파일 기능을 사용하여 대상을 얻는 방법이 있습니다.

@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 
+0

아이디어는 바로 가기를 해결하고 생성하지는 않습니다! (나는 완벽한 점수를 유지하기 위해 -1을주지 않을 것이다 !!!) –

+1

@LS_Dev 코드를 실제로 사용해 보셨습니까? 그렇다면 아무것도 생성하지 않는다는 것을 알 수 있습니다. wscript.shell 개체의 createshortcut 메서드를 사용하여 링크 대상을 확인합니다. –

+0

Ups ... 나는 링크를 열 수있는 방법을 찾고 "CreateShortcut' ["새 바로 가기를 만들거나 기존 바로 가기를 엽니 다 "(http://msdn.microsoft. com/en-us/library/xsy6k3ys.aspx) ... 사과드립니다. –

1

하이브리드 스크립트! 어리석은 작은 임시 파일이 없습니다.

::'<SUB>@echo off 
::'<SUB>set shortcut=%~1 
::'<SUB>if not defined shortcut goto 'usage 
::'<SUB>if not %shortcut:~-4%==.lnk (if not %shortcut:~-4%==.url (set errorlevel=1 
::'<SUB>goto 'usage)) 
::'<SUB>if not exist %shortcut% (echo Error: Nonexistent shortcut 
::'<SUB>set errorlevel=1 
::'<SUB>goto:EOF) 
::'<SUB>setlocal 
::'<SUB>for /f "delims=" %%T in ('cscript //nologo //e:vbs %~nx0 "%shortcut%"') do set thing=%%T 
::'<SUB>endlocal & set shortcut=%thing% 
::'<SUB>goto:EOF 
:'usage 
::'<SUB>echo command-line shortcut redirect utility 
::'<SUB>echo Usage: shortcut [file.lnk ^| file.url] 
::'<SUB>echo The resulting link will be output to the %%shortcut%% variable. 
::'<SUB>goto:EOF 
set WshShell = WScript.CreateObject("WScript.Shell") 
set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0)) 
wscript.Echo Lnk.TargetPath 

<SUB>substitute character 어디를 나타냅니다.

0

업데이트 : Wayne's World of IT에 훨씬 완전히 VBScript를 솔루션을 통해 발견하고, 약간 내 요구에 맞게 수정 :

If WScript.Arguments.UnNamed.Count = 1 Then 
strShortcut = WScript.Arguments.UnNamed(0) 
Else 
WScript.Echo "Please supply the name of an lnk file or directory to read, eg c:\test.lnk or c:\shortcuts" 
WScript.Quit(1) 
End If 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
If objFSO.FolderExists(strShortCut) Then 
Set objFolder = objFSO.getFolder(strShortcut) 
For Each objfile in objFolder.Files 
    If objfile.type = "Shortcut" Then 
    Call Readshortcut(objFile.Path, strProperties) 
    dtmCreationDate = objFile.DateCreated 
    WScript.Echo dtmCreationDate & "," & strProperties 
    End If 
Next 
ElseIf objFSO.FileExists(strShortCut) Then 
Call Readshortcut(strShortcut, strProperties) 
WScript.Echo strProperties 
Else 
WScript.Echo "Error: Could not read '" & strShortcut & "'" 
WScript.Quit(2) 
End If 
Set objFSO = Nothing 
Function Readshortcut(ByRef strShortcut, ByRef strProperties) 
set objWshShell = WScript.CreateObject("WScript.Shell") 
set objShellLink = objWshShell.CreateShortcut(strShortcut) 
strProperties = objShellLink.TargetPath & " " & objShellLink.Arguments 
Set objShellLink = Nothing 
Set objWshshell = Nothing 
End Function