Redirecting file names using a path without double quotes from the DIR command in Notepad ++ does not work, because Notepad ++ is a GUI application that cannot be read in file names from the standard STDIN input stream line by line.
Notepad ++ expects a space-separated list (with double quotes) of the file name (s) as command line parameters, in which double quotes around the file name without a path, relative path or absolute path are not always necessary depending on the characters in the file name and file paths.
My first suggestion:
@echo off setlocal EnableExtensions EnableDelayedExpansion set "Files=" for /F "delims=" %%I in ('dir zed.txt /AD /B /S 2^>nul') do set "Files=!Files! "%%I"" if not "!Files!" == "" notepad++.exe%Files% endlocal
This command code combines the found files into a long list of parameters, always starting with a space, and launches Notepad ++ with this list.
The problem with this simple code is that the length of the parameter list may exceed the maximum length for the string of the environment variable, if in fact there are many files with the file name zed.txt .
A simple solution would be to limit the number of files in Notepad ++, for example, to 25.
@echo off setlocal EnableExtensions EnableDelayedExpansion set "Files=" set "FileCount=0" for /F "delims=" %%I in ('dir zed.txt /AD /B /S 2^>nul') do ( set "Files=!Files! "%%I"" set /A FileCount+=1 if !FileCount! == 25 ( notepad++.exe!Files! set "Files=" set "FileCount=0" ) ) if not %FileCount% == 0 notepad++.exe%Files% endlocal
A better solution would be to check that each loop executes the current length of the environment variable before adding the next file name. But this will slow down the batch file, and usually the file names with paths are not so large that 25 files to execute Notepad ++ are really a problem.
Well, the theoretical single file name with a path may already be too long to assign an environment variable.
Note. . If the execution of the batch file is stopped after starting Notepad ++ and this behavior is not required, insert each Notepad++.exe line start "" to the left to start Notepad ++ in a separate process using an empty header line. Do not miss the "" after the START command before Notepad++.exe , as otherwise the first double quote (= the name of the first file with the path) will be interpreted as a header line.
To understand the commands used and how they work, open a command prompt window, run the following commands there, and carefully read all the help pages displayed for each command.
dir /?echo /?endlocal /?for /?if /?set /?setlocal /?start /?
See also a Microsoft article on Using Command Redirection Operators to Explain 2>nul . The redirection operator > escaped here with ^ to apply the STDERR redirection to the NUL device when executing the DIR command. This redirection is used to suppress the output of the error message with the DIR command if it cannot find zed.txt in the current directory or in any subdirectory.