Search code examples
windowsbatch-filecmdpipeio-redirection

Open multiple files from cmd dir output with notepad++


What I want to do: Use a dir command to find a bunch of text files, then open them all in Notepad++. Preferably in a single command without creating extra files. Normally, you can just say

notepad++ zed.txt ./ted/zed.txt ./red/zed.txt

But I need to open many files in a complex directory structure.

I feel like I should be able to do something like this:

dir /s/a/b "zed.txt" | notepad++

This does give me the output I want (recursively finds files and spits out just the filenames), but each on its own line and Notepad++ doesn't open them, it just opens and asks to create the file "notepad++" - which is empty.

Even using an extra file (undesirable, but not preferable) does not work:

c:\Users\tonip\Desktop\some_dir>dir /s/a/b "cmakelists.txt" > np.txt && notepad < np.txt

or

dir /s/a/b "cmakelists.txt" > np.txt
notepad++ < np.txt

N.B. Notepad++ directory is on my path.

Obviously, my re-direction skills are not good. Help is greatly appreciated.


Solution

  • for /f "delims=" %a IN ('dir /a-d /b /s *.csv') do call notepad++ "%a"
    

    This seems to work for me. Of course you will need to modify your 'dir /b' criteria to whatever files you are trying to match.

    This command loops through all the files output by dir (only csv files in my case) and opens them with notepad++. Be sure to include the /b after your dir command to only output filenames without all of the other information.