创建一个批处理文件,可以处理多个文件的拖放

Mid*_*tro 3 windows drag-and-drop batch-file tshark

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

目前,我可以使用以下批处理命令单独处理文件:

"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"
Run Code Online (Sandbox Code Playgroud)

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

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

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

Sac*_*Dee 5

使用%*代替%1

范例:

@echo off 

for %%a in (%*) do  (
"C:\Program Files\Wireshark\tshark.exe" -r "%%a" -Y "filter" -o "uat:user_dlts:\"User 8 (DLT=155)\",\"pxt\",\"0\",\"\",\"0\",\"\"" -o "gui.column.format:\"Info\",\"%%i\""> "%%a"".filter.txt"
)
Run Code Online (Sandbox Code Playgroud)

%%i正确的变量替换。

  • 只是一些笔记。如果放置在批处理文件中的任何文件在路径中都有空格,则将使用双引号引起来。另外,如果将足够长的路径的足够文件放到批处理文件中,则可能超出行数限制。在XP中为4096,在Windows 7中为8192。此外,其中任何带有“&”号的文件名都不能正确处理。处理所有参数的另一个选项也是使用SHIFT,然后检查%1是否不为空并循环回到标签。这是Jeb关于如何以不同方式执行此操作的观点的链接。http://stackoverflow.com/a/5370380/1417694 (4认同)

asc*_*pfl 5

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

: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
Run Code Online (Sandbox Code Playgroud)