创建一个批处理文件,可以处理多个文件的拖放 [英] Creating a Batch File that can Process a Drag and Drop of Multiple Files

查看:504
本文介绍了创建一个批处理文件,可以处理多个文件的拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过运行批处理文件来处理多个文件.我希望批处理文件能够接收给定的所有文件(又名转储;或拖放到文件中)并进行处理.

I am trying to process several files by running them through a batch file. I want the batch file to be able to take all the files its given (aka dumped; or dragged and dropped) and process them.

当前,我可以使用以下批处理命令分别处理文件:

Currently I can process the files individually with the following batch command:

"C:\Program Files\Wireshark\tshark.exe" -r %1 -Y "filter" -o "uat:user_dlts:\"User 8 (DLT=155)\",\"pxt\",\"0\",\"\",\"0\",\"\"" -o "gui.column.format:\"Info\",\"%%i\""> %1".filter.txt"

我希望做与上述相同的事情,但是能够将文件简单地拖放到要处理的批处理文件中.

I am looking to do the same thing as above, but with the ability to simply drag and drop the files onto the batch file to be processed.

对于上述批处理文件感到困惑的人:
-r读取输入文件,其完整文件地址(包括扩展名)被%1捕获
-Y过滤掉拖动的& ;;的某些部分.删除的文件
-o设置用于运行可执行文件的首选项(由"中的内容定义):tshark.exe
->将结果重定向到stdout
-%1".filter.txt"将结果输出到名为"draggedfilename.filter.txt"的新文件

For those confused about the above batch file:
-r Reads the input file, whose full file address (including extension) is captured by %1
-Y Filters out certain parts of the dragged & dropped file
-o Sets preferences (defined by stuff in the ""s) for running the executable: tshark.exe
- > redirects the results to stdout
- %1".filter.txt" outputs the results to a new file called "draggedfilename.filter.txt"

请避免在其他任何地方使用此代码,但要帮助我使用此代码(由于使用该代码的应用程序).为了隐私起见,我在此版本的代码中更改了几个标志. 让我知道您是否有任何疑问!

Please refrain from using this code anywhere else except helping me with this code (due to the application it is being used for). I changed several flags in this version of the code for privacy sake. Let me know if you have any questions!

推荐答案

您可以像这样使用gotoshift进行循环(有关详细信息,请参见rem注释):

You could go for a loop using goto and shift like this (see rem comments for details):

:LOOP
rem check first argument whether it is empty and quit loop in case;
rem `%1` is the argument as is; `%~1` removes surrounding quotes;
rem `"%~1"` therefore ensures that the argument is always enclosed within quotes:
if "%~1"=="" goto :END
rem the argument is passed over to the command to execute (`"%~1"`):
"C:\Program Files\Wireshark\tshark.exe" -r "%~1" -Y "filter" -o "uat:user_dlts:\"User 8 (DLT=155)\",\"pxt\",\"0\",\"\",\"0\",\"\"" -o "gui.column.format:\"Info\",\"%%i\""> "%~1.filter.txt"
rem `shift` makes the second argument (`%2`) to be the first (`%1`), the third (`%3`) to be the second (`%2`),...:
shift
rem go back to top:
goto :LOOP
:END

这篇关于创建一个批处理文件,可以处理多个文件的拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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