0

i am trying to open 20+ .txt files in a directory. i navigate the shell into the directory and tried to issue the following commands but they fail:

  1. ./*.txt //however t6.txt is a file in the directory and the command ./t6.txt works to open the single file

  2. notepad.exe Get-ChildItem .\*.txt since notepad.exe .\t6.txt works i tried this

  3. notepad.exe | Get-ChildItem *.txt opens an untitled blank notepad instance?!

i have found some really great answers that provide solutions including this one!

i think i have a fundamental misunderstanding of how the shell works underneath the hood. i am a lot surprised that i couldn't find this question elsewhere. i think that explanations to how these statement are dumb/stupid/bad may provide the context necessary for me to interpret the documentation properly and un-!#@$ my thinking. thanks for the help in advance

1 Answer 1

1

You will want a script like this:

get-childitem *.txt |foreach-object {
    notepad $_.name
}

This basically pipes the result object from a query for all txt files into the foreach-object, which then iterates through the resultset name by name and executes a command.

6
  • Or let the shell handle opening the file like gci *.txt | % {. $_.fullname}. That would allow for other file types to. Note that I never felt a need to open 20 files at once in 20 different processes so I doubt the usefullness. It would be faster to just select the 20 files, right click, open imo Commented Nov 1, 2021 at 20:14
  • yeah, i used to just right click and open but windows wont allow that anymore for some reason
    – ben hardin
    Commented Nov 1, 2021 at 20:20
  • I believe there's a limit to prevent users opening hundreds of files by accident but no doubt, that limit can be increased. Commented Nov 1, 2021 at 20:22
  • MultipleInvokePromptMinimum under KEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer apparently. Commented Nov 1, 2021 at 20:23
  • yeah, i just thought of that right as you posted it....it will let me open 15 at the moment. probably memory usage dependent?
    – ben hardin
    Commented Nov 1, 2021 at 20:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .