a question on directories

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • someguy9200
    New Member
    • Nov 2006
    • 2

    a question on directories

    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.
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    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.

    Comment

    • someguy9200
      New Member
      • Nov 2006
      • 2

      #3
      I have no idea what you are talking about.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by someguy9200
        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.

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          Originally posted by someguy9200
          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:
          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")
          You can set the current working directory with os.chdir(path).

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by someguy9200
            I have no idea what you are talking about.
            Are you ask about how to create directories in xp?

            Comment

            Working...