HOW TO

Create a directory using the MsgBox class

Last Published: April 25, 2020

Summary

The FileDialog class only creates files, not directories. ArcView does not support the ability to create directories. You can, however, use the Avenue MsgBox class to access the mkdir command to create a directory. The following code shows how to do this.

Procedure



  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy and paste the following code in the new script window.

    Code:
    '-- Script: CreateDirectory.ave
    '
    '-- This script prompts you through their existing directory
    '-- structure, and allows you to create a new subdirectory
    '-- anywhere on any drive.
    '
    '-- The script only checks the existence of the drive and the
    '-- paths exist, it does not check if you have write-access
    '-- to create a new directory in the chosen location.
    '
    '-- You could add the string "HERE" to the
    'list of directories.
    '-- You pick the "HERE" string to exit the 'while' loop
    '-- instead of hitting the Cancel button to exit the loop.
    '
    '-- Near the bottom of this script, there
    'is a "System.Execute()" line,
    '-- adjust this string to reflect the actual location of
    '-- your command.com file.
    '
    '-- You could also modify the script to return an existing
    '-- directory, instead of writing a
    '-- new one.

    alphabet = "CDEFGHIJKLMNOPQRSTUVWXYZ"
    driveList = {}
    for each i in 0..23
    str = alphabet.Middle(i, 1)
    str = str + ":\"
    if (File.Exists(str.AsFileName))
    then
    driveList.Add(str)
    end
    end
    selPath=MsgBox.ListAsString
    (driveList,
    "Choose drive",
    "Create Directory")
    sel = "a"
    while (sel <> nil)
    subdirpathList = {}
    dirContentsList = selPath.AsFileName.Read("*.*")
    for each item in dirContentsList
    if (item.IsDir)
    then
    subdirpathList.Add(item)
    end
    end
    sel = MsgBox.ListAsString(subdirpathList,
    "Choose directory. When you are"++
    "at the level where you want to"++
    "create a new directory, hit CANCEL.",
    "Create Directory")
    if (sel <> nil)
    then
    selPath = sel.AsString
    end
    end
    newSubDir = MsgBox.Input
    ("Enter the name of the new subdirectory"++
    "to be placed inside"++selPath+".",
    "Create Directory",
    "subdirectory name goes here")
    newSubDir = selPath+"\"+newSubDir
    ans = MsgBox.YesNo("Is this the new subdirectory?"+NL+
    newSubDir, "Create Directory", TRUE)
    if (ans = FALSE)
    then
    MsgBox.Info("Subdirectory creation halted"+NL+
    "Try again later.","Create Directory")
    return nil
    end
    System.Execute("C:\winnt\system32\command.com /c mkdir" ++
    newSubDir)
    '
    '-- End of Script: CreateDirectory.ave

  3. Compile and run the script. Follow the directions offered in the dialog boxes.

    Note:
    Make sure your paths are 8.3 compliant otherwise this will not work.

    For a file or path name to be 8.3 compliant, the prefix portion of the name must not be longer than 8 characters. The suffix portion of the name must be 3 characters long exactly. Additionally, the path or file name must not contain special characters, such as, spaces, #, $, and so forth.


Article ID:000002690

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic