HOW TO
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.
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
Note:
Make sure your paths are 8.3 compliant otherwise this will not work.
Article ID:000002690
Get help from ArcGIS experts
Download the Esri Support App