简体   繁体   中英

How do I make my python program (C-Bos) open only files with ".bos.py" at the end?

So C-Bos has programs that are.py files obv and you can open them through the main program or just open them like any other.py file. And I want it to only recognize files with.bos.py at the end.

I asked ChatGPT but they made it only open files called.bos.py lmao. Oh and when I tried to open files with that (I renamed a program to.bos.py lol) C-Bos just crashed. I am using elif statements for this btw the code (that works) for that is:

elif(cmd=="Run"):
    ope = input("file:")
    subprocess.Popen(ope, shell=True)

So yeah end of post.

What about usibg glob for this? I don't understand what you meant by opening (run it or open in notepad, idle) so I copied the subprocess line.

import glob
import subprocess

for file in glob.glob("*.bos.py"):
    subprocess.Popen(file, shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM