In Microsoft Windows 7
I have two Kotlin source codes in C:\new
directory:
- hello1.kt
- hello2.kt
I can compile them separately in command line which its current working directory is C:\
, for example >kotlinc hello1.kt
. But when I try to do batch compile, I get an error:
C:\new>kotlinc *.kt
error: source file or directory not found: *.kt
Notes:
- Result of
kotlinc .\*.kt
was the same. > dir *.kt
lists.kt
files correctly, so the problem could not be in about*
wildcard.$ kotlinc *.kt
works inLinux
without error.
I want to know what causes the problem? Is there a way for doing batch compile in Microsoft Windows
?
It looks like
kotlinc.exe
does not support wildcard patterns as an argument. So there must be usedkotlinc hello1.kt hello2.kt
on Windows.The shell interpreters on Linux/Mac expand a wildcard pattern like
*.kt
to a list of argument strings with matching file/folder names before executing the executable. So the shell interpreters on Linux/Mac do not callkotlinc
with*.kt
, but call the executable withhello1.kt hello2.kt
.The Windows command processor
cmd.exe
does not offer such a wildcard expansion in arguments list of an executable. The executable itself must support an argument with a wildcard pattern and search itself for matching files/folders.A Windows batch file solution would be following code working for all file names except file names with an exclamation mark:
A slower solution working also for
.kt
file names with one or more!
in file name.Please note that the list of file names is not unlimited. The maximum length for an environment variable definition is 8192 characters which includes the variable name, the equal sign, the string value assigned to the environment variable and the terminating null byte. The file names added to the list are without path. So this limitation should be no problem here as long as not several hundreds of
.kt
files should be compiled with one execution ofkotlinc.exe
.To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
call /?
echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
popd /?
pushd /?
rem /?
set /?
setlocal /?
See also: