9.20 Directory object
Description
You can edit directory and file structures with the Directory object. Additionally you can browse directories. Like at the
File object you can only access the game directory and its subdirectories.
List of methods/properties
Name | Type | Short description |
CreateDir | Method | Creates a directory |
RemoveDir | Method | Removes an empty(!) directory |
Rename | Method | Renames a file/directory or moves it |
CopyFile | Method | Copies a file |
DeleteFile | Method | Deletes a file |
GetAttributes | Method | Returns the attributes of a file/directory |
SetAttributes | Method | Sets the attributes of a file/directory |
FindFirst | Method | Starts to browse a directory |
FindNext | Method | Continues the browsing of a directory |
FindClose | Method | Stops the browsing of a directory |
Description
With this method you can create a new directory. The name of the directory has a relative path to the game directory.
Syntax
1
Directory.CreateDir(Directory)
Return value
None
Type
Method
Parameter: Directory
Description
Specifies the name (inclusive the relative path if necessary) of the new directory. You can only create directories inside of the game directory (and subdirectories).
Data type
String
Example
1
2
$
Directory.CreateDir("Picture\Content")
At the end a new subdirectory whould be created with the name "Content" in the Picture folder.
Description
With this method you can remove an empty directory. The name of the directory has a relative path to the game directory.
Syntax
1
Directory.RemoveDir(Directory)
Return value
None
Type
Method
Parameter: Directory
Description
Specifies the name (inclusive the relative path if necessary) of the directory that shall be removed. You can only remove directories inside of the game directory (and subdirectories).
Data type
String
Example
1
2
$
Directory.RemoveDir("Testfolder")
At the end the directory with the name "Testfolder"e; (which is inside of the game directory) whould be removed.
Description
With this method you can rename or move files and directories. A file/directory is moved if it gets a new path (without a new name). Otherwise it will be renamed (and moved if the path is different).
Syntax
1
Directory.Rename(OldPath, NewPath)
Return value
None
Type
Method
Parameter: OldPath
Description
Specifies the current (relative) path of the file/directory. You can only rename files/directories inside of the game directory (and subdirectories).
Data type
String
Parameter: NewPath
Description
Specifies the new (relative) path of the file/directory. You can only rename files/directories inside of the game directory (and subdirectories).
Data type
String
Example
1
2
3
4
5
$
Directory.Rename("Folder old\File.txt",
"Folder new\File.txt);
Directory.Rename("Folder old\Subfolder",
"Folder old\Subfolder2)
At the end the file "File.txt" whould be moved from the directory "Folder old" into the directory "Folder new" (Line 2 & 3). Additionally the directory "Subfolder" whould be renamed to "Subfolder2" (Line 4 & 5).
Description
With this method you can copy files.
Syntax
1
Directory.CopyFile(SourceFile, DestinationFile)
Return value
None
Type
Method
Parameter: SourceFile
Description
Specifies the (relative) path of the file which shall be copied. You can only copy files inside of the game directory (and subdirectories).
Data type
String
Parameter: DestinationFile
Description
Specifies the (relative) path of the copy. You can only copy files inside of the game directory (and subdirectories).
Data type
String
Example
1
2
$
Directory.CopyFile("RPG_RT.exe", "RPG_RT2.exe")
At the end the file "RPG_RT.exe" whould be copied as "RPG_RT2.exe".
Description
With this method you can delete files.
Syntax
1
Directory.DeleteFile(File)
Return value
None
Type
Method
Parameter: File
Description
Specifies the (relative) path of the file that shall be deleted. You can only delete files inside of the game directory (and subdirectories).
Data type
String
Example
1
2
$
Directory.DeleteFile("Test.txt")
At the end the file "Test.txt" whould be deleted.
Description
With this method you can retrieve the attributes of a file/directory. The return value is a combination of the
file attribute constants.
Syntax
1
Directory.GetAttributes(Path)
Return value
Dword
Type
Method
Parameter: Path
Description
Specifies the (relative) path of the file/directory whose attributes shall be retrieved. You can only access the attributes of files/directories inside of the game directory (and subdirectories).
Data type
String
Example
1
2
$
v[1] = Directory.GetAttributes("Test.txt")
Description
With this method you can set the attributes of a file/directory. You can use (and combine) the
file attribute constants for this. You can't convert directories into files (or vice versa).
Syntax
1
Directory.SetAttributes(Path, NewAttributes)
Return value
None
Type
Method
Parameter: Path
Description
Specifies the (relative) path of the file/directory whose attributes shall be set. You can only set the attributes of files/directories inside of the game directory (and subdirectories).
Data type
String
Parameter: NewAttributes
Description
Specifies the new attributes of the file/directory. You can use (and combine) the
file attribute constants for this. Files may not have the attribute FILE_ATTRIBUTE_DIRECTORY.
Data type
Dword
Example
1
2
$
Directory.SetAttributes("Test.txt", FILE_ATTRIBUTE_HIDDEN)
At the end the file "Test.txt" whould be marked as hidden.
Description
With this method you can start to browse a directory. You can specify the search options with the parameter search pattern. To continue the browsing (and even find all files/directories) you must call the method
FindNext in a loop. During each browsing you find first the directories "." and "..". "." is the current directory and ".." is the parent directory. If you don't need this information you should skip it. This method is equivalent to the windows function FindFirstFile.
Syntax
1
Directory.FindFirst(SearchPattern)
Return value
String
Type
Method
Parameter: SearchPattern
Description
Specifies the (relative) path of the browsing directory including the
placeholders. You can use the asterisk (*) and the question mark (?) as placeholder. The asterisk stands for any number of unknown chars and the question mark stand for exact one unknown char. To browse effectively you must use at least one of these placeholders. You can only access files/directories inside of the game directory (and subdirectories).
Data type
String
Example
1
2
$
a[1] = Directory.FindFirst("*.lmu")
At the end a[1] whould contain the filename of the first map of the game (= files in the gamedirectory with the extension lmu are maps).
Description
After starting to browse a directory using the
FindFirst method you can continue browsing using this method. After each call this method returns the filename of the next matching file/directory. If this method returns an empty string then the browsing is finished and it must be closed using
FindClose.
Syntax
Return value
String
Type
Method
Example
1
2
$
a[1] = Directory.FindNext()
At the end a[1] whould contain the next matching file/directory of a browsing. This command should be used in a loop until it returns an empty string (in this example a[1] whould be empty).
Description
With this method you can close a previously started browsing.
Syntax
Return value
None
Type
Method
Example
1
2
$
Directory.FindClose()