通过将文件拖放到批处理文件中来打开文件 [英] Open file by dragging and dropping it onto batch file

查看:166
本文介绍了通过将文件拖放到批处理文件中来打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道如何将文件图标拖放到程序上或该程序的快捷方式将如何使用该程序打开文件?好吧,我有一个打开程序的批处理,我要执行的操作是将一个文件拖放到批处理文件图标上,然后使用该批处理所指向的程序打开该文件.有没有可以执行此操作的批处理脚本?

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.

推荐答案

下面是一个批处理脚本的示例,如果传递的参数是一个文件夹,它将可以打开,可以使用Notepad.exe拖放任何文件以将其打开.与Explorer.exe

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
::**********************************************************

这篇关于通过将文件拖放到批处理文件中来打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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