2017-06-15 66 views
1

您知道如何將文件圖標拖放到程序或程序的快捷方式上,它將使用該程序打開文件?那麼我有一個批次打開一個程序,我想要做的是將一個文件拖放到批處理文件圖標上,並用該批次指向的程序打開該文件。有沒有可以做到這一點的批處理腳本?通過將文件拖放到批處理文件上打開文件

我想這樣做的原因是,我有多個文件旁邊的多個快捷方式,我想這些快捷方式只是指向一個批處理文件,所以這是程序的路徑變化我只需要改變腳本在批處理文件中,而不是一堆快捷方式。

+3

打開要訪問拖動文件的例子並放在一個批處理文件中,將其稱爲['%1'](http://ss64.com/nt/syntax-args.html)(另請參閱'call/?'獲取更多信息);你可以在你的批處理文件中寫入''D:\ path \ to \ your \ program.exe「」%〜1「'用'program.exe'打開文件... – aschipfl

回答

2

這裏是一個批處理腳本,可以拖放任何文件與Notepad.exe打開它,如果傳遞的參數是一個文件夾,它會與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 
::********************************************************** 
相關問題