By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

a question on directories

P: 2
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.
Nov 27 '06 #1
Share this Question
Share on Google+
5 Replies


bartonc
Expert 5K+
P: 6,596
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.
Nov 27 '06 #2

P: 2
I have no idea what you are talking about.
Nov 27 '06 #3

bartonc
Expert 5K+
P: 6,596
I have no idea what you are talking about.
The Python documentation is something that you MUST be able to put your hands on and is the FIRST place to start learning. If your system was properly installed, there in Start->Programs->Python 2.4->Python Manuals. The first page is an index that starts with a tutorial (start here). Then comes the Global Module Index. Follow this link and scroll down to os and ospath and begin your study.
Nov 27 '06 #4

bvdet
Expert Mod 2.5K+
P: 2,851
I have no idea what you are talking about.
I wrote some applications that read the current working directory and create a directory if it does not exist. These examples may give you an idea about what Barton was talking about:
Expand|Select|Wrap|Line Numbers
  1. # snip
  2.     import os
  3.     from macrolib.FileDefaults import import_data, export_data, job_Defaults_path, data_Defaults_path, check_Defaults_dir
  4.     # system path for default values files
  5.     # auto save path
  6.     default_file_path = data_Defaults_path()
  7.     # user save path
  8.     job_default_file_path = os.path.join(job_Defaults_path(), "Beam_BPL_Pourstop")
  9.     # default values file name
  10.     def_file = "Beam_BPL_Pourstop_v1_12.txt"
  11.     script_name = "Beam_BPL_Pourstop_v1.12.py"
  12.     # default to enable or disable the automatic importing and exporting of dialog dictionary variables
  13.     # ("Enable", "Disable")
  14.     enable_default_import_export = "Enable"
  15.     """
  16.         The saving and importing of default files requires that a subdirectory 'Defaults' exists.
  17.         The 'Defaults' directory for automatic import/export is returned by 'data_Defaults_path()' ('SDS/2 root data/macro/Defaults)
  18.         The 'Defaults' directory for user import/export is returned by 'job_Defaults_path()'('job directory'/macro/Defaults')
  19.     """
  20.     # check if automatic defaults directory exists
  21.     if enable_default_import_export == "Enable":
  22.         if not check_Defaults_dir(default_file_path):
  23.             Warning("Edit the parametric file and change variable 'enable_default_import_export' value to 'Disable'")
  24.  
  25.     # check if user defaults directory exists
  26.     if not check_Defaults_dir(job_default_file_path):
  27.         job_default_file_path = default_file_path
  28.  
  29.     # dialog box image file path and names
  30.     image_path = os.path.join(os.getcwd(), "macro", "Images")
  31.     image_name = os.path.join(image_path, "Beam_BPL_Pourstop.gif")
  32. # snip
Expand|Select|Wrap|Line Numbers
  1. # Create the 'Defaults' directory if it does not exist
  2. # Example: 'C:\SDS2_7.0\jobs\607_Great_Wolf\macro' is an existing path
  3. # Make directory 'C:\SDS2_7.0\jobs\607_Great_Wolf\macro\Defaults'
  4. # Return 1 if directory exists or directory creation is successful
  5.  
  6. import os
  7. import macrolib.pickle
  8.  
  9. def check_Defaults_dir(file_path):
  10.     from param import Warning, yes_or_no
  11.     if not os.path.isdir(file_path):
  12.         if yes_or_no("The directory path does not exist. Do you want to create directory '%s'?" % (file_path)):
  13.             try:
  14.                 os.makedirs(file_path)
  15.                 return True
  16.             except OSError, e:
  17.                 Warning("Could not create directory %s: %s" % (file_path, e))
  18.                 return False
  19.         else:
  20.             return False
  21.     return True
  22.  
  23. ###############################################################################
  24. # return the path to the job default values directory
  25. # format - 'SDS/2 root data'\jobs\'name of job'\macro\Defaults
  26. def job_Defaults_path():
  27.     from job import JobName
  28.     return os.path.join(os.getcwd(), "jobs", JobName(), "macro", "Defaults")
  29.  
  30. ###############################################################################
  31. # return the path to the data default values directory
  32. # format - 'SDS/2 root data'\macro\Defaults
  33. def data_Defaults_path():
  34.     return os.path.join(os.getcwd(), "macro", "Defaults")
You can set the current working directory with os.chdir(path).
Nov 28 '06 #5

bartonc
Expert 5K+
P: 6,596
I have no idea what you are talking about.
Are you ask about how to create directories in xp?
Nov 28 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.