For example, opening many text files with notepad++ via python script. I need to open every file in a directory.
Asked
Active
Viewed 956 times
-1
-
Iterate over each file in your directory, opening each file via `with open() as file:` construct. – Christian Dean Dec 28 '16 at 06:03
-
@leaf no I think he wants to open in GUI mode. In linux you can do `gedit *` inside folder. dunno about windows. – Mohammad Yusuf Dec 28 '16 at 06:04
-
Are you using windows or linux? – Mohammad Yusuf Dec 28 '16 at 06:06
-
1You can use `subprocess.popen()` in a loop to execute a shell command on each file. – Barmar Dec 28 '16 at 06:07
-
windows 7, 64 bit. – Darkseid Dec 28 '16 at 06:07
-
1Try this: `Start notepad++ *.txt` in powershell after entering the folder. – Mohammad Yusuf Dec 28 '16 at 06:11
-
@Community♦ this is not a duplicate. It is very closely related, but not a duplicate. – Christian Dean Dec 28 '16 at 06:12
-
@leaf It's a bot :P. Can it process comments? – Mohammad Yusuf Dec 28 '16 at 06:14
-
Notepad++ provides Python module. Check this http://npppythonscript.sourceforge.net/docs/latest/notepad.html – shrishinde Dec 28 '16 at 06:15
-
@MYGz I know :-) I _was_ going to ask somebody to reopen the question, but its fine. – Christian Dean Dec 28 '16 at 06:44
1 Answers
1
You can use the glob and fileinput together
import fileinput
from glob import glob
file = glob('Sample*.txt')
for line in fileinput.input(file):
pass
If you want to iterate multiple files then use :
for x in fileinput.input(['patterns.in', 'sample*.txt']):
print x

Ranadip Dutta
- 8,857
- 3
- 29
- 45