Reputation: 23
So maybe Python works differently than I am imagining it in my head. What I want to do is create a directory, "cd" into it, create another directory and then "cd" into that one. Every time I print out what directory I am in, i keep getting the one my current .py is in. Am I missing something?
#variables
current_dir = os.getcwd()
build_dir = "./../Documents/Releases/"
prod_folder = "./Products"
prod_dir = "./Products/Project"
# Path to directory
print("Current Directory: %s" % current_dir)
os.chdir(build_dir)
build_no = input("Enter the build branch/build number: ")
#created new directory
print("Current Directory: %s" % current_dir)
if not os.path.exists(build_no):
os.mkdir(build_no)
print("Directory ", build_no, " created.")
else:
print("Directory ", build_no, "already exists.")
# This works fine up to here. I "cd" into where I need to and the new
# folder/directory is created, after here is where I am having issues.
#cd into Products/Project
print("Current Directory: %s" % current_dir)
if not os.path.exists(prod_folder):
os.mkdir(prod_folder)
os.chdir(prod_dir)
Upvotes: 0
Views: 49
Reputation: 23
So this issue has been resolved but I have a follow up task I want to do. One of my goals with this code is to automate a process. Part of that process is wanted to open xcode and then archive the .xcworkspace I open. One of my co-workers told me that was possible. I am still learning Python, but I am not sure how I would automate mouse clicks or commands on another program. Any tips?
Upvotes: 0
Reputation: 71
Please refer to @Alassane comment for the fixing the issue. As for why it is happening, all you are doing is calling the current_dir
variable that has been set the when the os.getcwd()
function call happened in the first line. So when ever you are referring to the variable current_dir
it is just printing the same value over and over again.
Upvotes: 0
Reputation: 4767
You should call print("Current Directory: %s" % os.getcwd())
. By using print("Current Directory: %s" % current_dir)
, you're printing the same variable over and over.
Upvotes: 2