title: How to execute a python script in a different directory?
body: <p><strong>Solved</strong> see my answer below for anyone who might find this helpful.</p>
  
  <p>I have two scripts a.py and b.py.
  In my current directory "C:\Users\MyName\Desktop\MAIN", I run > python a.py.</p>
  
  <p>The first script, a.py runs in my current directory, does something to a bunch of files and creates a new directory (testA) with the edited versions of those files which are simultaneously moved into that new directory. Then I need to run b.py for the files in testA.</p>
  
  <p>As a beginner, I would just copy and paste my b.py script into testA and execute the command again "> python b.py", which runs some commands on those new files and creates another folder (testB) with those edited files.</p>
  
  <p>I am trying to eliminate the hassle of waiting for a.py to finish, move into that new directory, paste b.py, and then run b.py. I am trying to write a bash script that executes these scripts while maintaining my hierarchy of directories.</p>
  
  <pre><code>#!/usr/bin/env bash
   python a.py &amp;&amp; python b.py
  </code></pre>
  
  <p>Script a.py runs smoothly, but b.py does not execute at all. There are no error messages coming up about b.py failing, I just think it cannot execute because once a.py is done, b.py does not exist in that NEW directory.
  Is there a small script I can add within b.py that moves it into the new directory? I actually tried changing b.py directory paths as well but it did not work.</p>
  
  <p>For example in b.py:</p>
  
  <pre><code>mydir = os.getcwd() # would be the same path as a.py
  mydir_new = os.chdir(mydir+"\\testA")
  </code></pre>
  
  <p>I changed mydirs to mydir_new in all instances within b.py, but that also made no difference...I also don't know how to move a script into a new directory within bash.</p>
  
  <p>As a little flowchart of the folders:</p>
  
  <pre><code>MAIN # main folder with unedited files and both a.py and b.py scripts
  |
  | (execute a.py)
  |
  --------testA # first folder created with first edits of files
           |
           | (execute b.py)
           |
           --------------testB # final folder created with final edits of files
  </code></pre>
  
  <p>TLDR: How do I execute a.py and b.py from the main test folder (bash script style?), if b.py relies on files created and stored in testA. Normally I copy and paste b.py into testA, then run b.py - but now I have 200+ files so copying and pasting is a waste of time.</p>