Solved Python Help

Discussion in 'All Software Support' started by Evan Eldemachki, Jun 11, 2012.


Thread Status:
Not open for further replies.
  1. Evan Eldemachki Bronze Member

    Bronze
    Message Count:
    72
    Likes Received:
    3
    My System
    Loading...
    Does anyone know how to open a file from it's own operating system, but while staying in the same directory? This is what I want to do:
    Code:
    import os
    os.startfile("Folder/Test.bat")
    But the Folder is in the same directory as the script.py, and I need the script to be portable, so it needs to run from it's own folder. Does anyone know how a script to open the .bat file that's in the same directory?
    Thanks for your help

  2. samuria Network Specialist

    PCHF Staff
    Message Count:
    16,361
    Likes Received:
    974
    My System
    Loading...
    Try these examples normally you give the full unc path if you just give the file name it defaults to the current folder and the dos path
    Evan Eldemachki likes this.
  3. Evan Eldemachki Bronze Member

    Bronze
    Message Count:
    72
    Likes Received:
    3
    My System
    Loading...
    Oh really? Does that mean that if I put the file in the same folder and use something like this:
    Code:
    os.startfile("Test.bat")
    then it will open the batch file without specifying the path? That would make it a lot easier to do, I just used the folder for organization purposes.
    P.S. I can't try it now because I'm on my phone but thanks I'll test it when I get home
  4. Google Advertisement

  5. Evan Eldemachki Bronze Member

    Bronze
    Message Count:
    72
    Likes Received:
    3
    My System
    Loading...
    Okay thanks I just tried it and it worked perfectly :)
  6. samuria Network Specialist

    PCHF Staff
    Message Count:
    16,361
    Likes Received:
    974
    My System
    Loading...
    It always looks first in the current folder for a file then if you open a cmd prompt and type set you will see the path if it cant find the file in the current folder it then looks in all the folders in the path.

    Can we mark as solved
    Evan Eldemachki likes this.
  7. Evan Eldemachki Bronze Member

    Bronze
    Message Count:
    72
    Likes Received:
    3
    My System
    Loading...
    Yeah sure thanks
  8. AndroidOS PCHF SMR Graduate

    PCHF Staff
    Message Count:
    1,987
    Likes Received:
    239
    My System
    Loading...
    I've marked this as solved, Evan. :)
    Evan Eldemachki likes this.

Python Help

Thread Status:
Not open for further replies.