1

In windows explorer when I drag and drop 100 files over a batch file, I get an error saying that the "data area passed to a system call was too small"

I generated the batch file to take 100 arguments like so, thinking it would work

MyProg.exe %1 %2 %3 %4 %5 ... %100

MyProg takes a bunch of paths and does things to them.

So now my solution is

for %%X in (*.my_ext) do (
    MyProg.exe %%X
)

But that is initializing my program again and again since I am just passing one file to it, which sort of defeats the purpose of accepting an arbitrary number of arguments and this start-up + finish is slowing things down.

Ideally, I would like to just pass all files to my program and let it run. How would I accomplish this?

EDIT:

One idea I'm going for is this one: How to concatenate strings in a Windows batch file?

My solution now looks like this. I have two batch files get_files.bat and main.bat

get_files.bat

@echo off
set myvar=myProg.exe
for /r %%i in (*.my_ext) DO call :concat "%%i"
echo %myvar%
goto :eof

:concat
set myvar=%myvar% %1
goto :eof

main.bat

call get_files.bat > out.bat
call out.bat

I first create the command I want to call, and then I call it. This allows me to pass 100's of paths that match the given crieria to my program, though it seems like at some point I reach the limit on how long the input string can be.

The ideal solution would look something like building as long of a list as possible and passing that list to the program, and then repeat until all files have been processed. The files may be searched recursively, etc.

4

1 回答 1

0

Microsoft 已发布支持文章命令提示符 (cmd.exe) 命令行字符串限制

在运行 Microsoft Windows XP 或更高版本的计算机上,您可以在命令提示符处使用的最大字符串长度为 8191 个字符。在运行 Microsoft Windows 2000 或 Windows NT 4.0 的计算机上,您可以在命令提示符处使用的最大字符串长度为 2047 个字符。

避免在执行具有许多文件的应用程序时出现这种限制的最佳方法是使用Andriy M也建议的列表文件。

例如,WinRAR 将文件名@以列表文件的名称开头,其中包含要压缩/提取的文件的名称。

文本编辑器 UltraEdit 支持命令行选项/f"name of list file"以逐行打开指定列表文件中列出的所有文件。

并且文件管理器 Total Commander%L, %l, %F, %f, %D, %d, %WL, %WF, %UL, %UF在命令行中支持由 Total Commander 调用的应用程序。在其中一个占位符出现的情况下,Total Commander 在临时文件的目录中创建一个列表文件,其中将所选文件的名称逐行写入其中,然后使用此列表文件的名称启动应用程序。Total Commander 甚至会监督启动的应用程序,并在应用程序终止后删除列表文件。

我认为,在您的情况下,您的应用程序最有可能在逐行处理此文件中列出的所有文件后删除列表文件本身。

于 2014-09-06T11:08:35.563 回答