问题
You know how if you drag and drop a files icon over a program or shortcut to a program it will open the file with that program? Well I have a batch that opens a program and what I want it to do is take a file that was dragged and dropped onto the batch files icon and open that file with the program the batch is pointing to. Is there any batch script that can do that?
The reason I want to do this is that I have multiple files next to multiple shortcuts and I want to have those shortcuts just point to a batch file so that is the path of the program ever changes I only have to change the script in the batch file and not a while bunch of shortcuts.
回答1:
Here is an example of a batch script that can be drag and drop any file to open it with Notepad.exe
if the argument passed is a folder it will open with Explorer.exe
@echo off
Title Drag and drop a file to open with Notepad
Mode con cols=60 lines=3
IF [%1] EQU [] Goto:Error
CD /D "%~1">nul 2>&1 && Goto:Explorer_Folder || Goto :OpenFile
Exit /b
::**********************************************************
:OpenFile <File>
Start "Drag and Drop" "%windir%\system32\Notepad.exe" "%~1"
Exit /b
::**********************************************************
:Explorer_Folder <Folder>
Explorer "%~1"
Exit /b
::**********************************************************
:Error
Color 0C & echo(
ECHO You must drag and drop a file on this batch program
Timeout /T 5 /NoBreak >nul
Exit /b
::**********************************************************
来源:https://stackoverflow.com/questions/44577446/open-file-by-dragging-and-dropping-it-onto-batch-file