I have windows xp and I have a few questions about directories. How do you make directories and how do you set them as your current directory. I need to know how to do this so I can use scripts on python.
a question on directories
Collapse
X
-
Tags: None
-
There is a two library modules called os and ospath with lots of functions to make sure that strings look like valid path names for whatever platform you are on and functions for getting and setting the current working directory. Python 2.4 docs sections 6.1 and 6.2. -
-
Originally posted by someguy9200I have no idea what you are talking about.Comment
-
Originally posted by someguy9200I have no idea what you are talking about.
Code:# snip import os from macrolib.FileDefaults import import_data, export_data, job_Defaults_path, data_Defaults_path, check_Defaults_dir # system path for default values files # auto save path default_file_path = data_Defaults_path() # user save path job_default_file_path = os.path.join(job_Defaults_path(), "Beam_BPL_Pourstop") # default values file name def_file = "Beam_BPL_Pourstop_v1_12.txt" script_name = "Beam_BPL_Pourstop_v1.12.py" # default to enable or disable the automatic importing and exporting of dialog dictionary variables # ("Enable", "Disable") enable_default_import_export = "Enable" """ The saving and importing of default files requires that a subdirectory 'Defaults' exists. The 'Defaults' directory for automatic import/export is returned by 'data_Defaults_path()' ('SDS/2 root data/macro/Defaults) The 'Defaults' directory for user import/export is returned by 'job_Defaults_path()'('job directory'/macro/Defaults') """ # check if automatic defaults directory exists if enable_default_import_export == "Enable": if not check_Defaults_dir(default_file_path): Warning("Edit the parametric file and change variable 'enable_default_import_export' value to 'Disable'") # check if user defaults directory exists if not check_Defaults_dir(job_default_file_path): job_default_file_path = default_file_path # dialog box image file path and names image_path = os.path.join(os.getcwd(), "macro", "Images") image_name = os.path.join(image_path, "Beam_BPL_Pourstop.gif") # snip
Code:# Create the 'Defaults' directory if it does not exist # Example: 'C:\SDS2_7.0\jobs\607_Great_Wolf\macro' is an existing path # Make directory 'C:\SDS2_7.0\jobs\607_Great_Wolf\macro\Defaults' # Return 1 if directory exists or directory creation is successful import os import macrolib.pickle def check_Defaults_dir(file_path): from param import Warning, yes_or_no if not os.path.isdir(file_path): if yes_or_no("The directory path does not exist. Do you want to create directory '%s'?" % (file_path)): try: os.makedirs(file_path) return True except OSError, e: Warning("Could not create directory %s: %s" % (file_path, e)) return False else: return False return True ############################################################################### # return the path to the job default values directory # format - 'SDS/2 root data'\jobs\'name of job'\macro\Defaults def job_Defaults_path(): from job import JobName return os.path.join(os.getcwd(), "jobs", JobName(), "macro", "Defaults") ############################################################################### # return the path to the data default values directory # format - 'SDS/2 root data'\macro\Defaults def data_Defaults_path(): return os.path.join(os.getcwd(), "macro", "Defaults")
Comment
Comment