Directory is a data type that allows the management of system directories. It simplifies the development of applications that need to execute actions over system directories and files.
Use Directory data type for typical operations such as creating, copying, moving, renaming and deleting directories. You can also use the Directory data type to obtain the directory attributes such as modification date, time and size.
By defining variables based on this data type you are able to set and use the following properties and methods.
|
Selects the directory in the specified path. |
|
Returns the result of the last operation. It has one of the following values:
0: Operation completed successfully.
1: Invalid directory instance - when the Source property was not set.
2: Directory does not exist.
3: Directory already exists.
4: Directory not empty.
100: Security error.
-1: Undefined error |
|
Returns the result description of the last operation |
|
The directory where files related to the application are stored. |
|
The directory where temporary files of the application are stored.
C# - It is implemented using Path.GetTempPath() method.
Java - It returns the value of System.getProperty("java.io.tmpdir"). |
|
The path to the external storage device, if it exists, otherwise this property has the value of the property "ApplicationDataPath". |
|
The directory where the cache files of the application are stored. |
For more information about the static properties of this data type please refer to Directory Data Type Static properties.
Note: CacheFilesPath are available since GeneXus 16 upgrade 4 for iOS generator.
CacheFilesPath are available since GeneXus 16 upgrade 9 for Android generator.
Creates a new directory in the specified source.
Directory name (character)
&directory.Source="c:\temp"
&directory.create()
Deletes the source directory.
&directory.delete()
Checks whether the directory specified in source exists.
Boolean
If &directory.exists()
Msg("The directory exists!")
Else
Msg("The directory does not exist!")
EndIf
Returns the source directory's name.
Character
&directory.Source = "c:\temp"
Msg(&directory.GetName()) // screen shows: temp
Returns the absolute name of the source directory.
Character
&directory.Source="c:\temp"
Msg(&directory.GetAbsoluteName()) // screen shows: c:\temp
Renames the source directory. It can be also used to move the directory changing its current path.
The new name of the directory (Character).
&directory.Rename("d:\temp2")
Returns the names of files in the source directory. Also, a filter can be specified using extension-wildcards or end-with patterns.
Filter (Character)
for &auxFile in &directory.GetFiles('*.txt')
// do something with .txt auxFile
endfor
where &auxFile is defined as a File variable.
Returns the names of every directory in the source directory.
for &auxDir in &directory.GetDirectories()
// do something with auxDir
endfor
where &auxDir is defined as a Directory variable.
Directory data type handles directories that are in the local file system by default. But when it is returned by a method of the Storage Provider API, then it refers to a directory located in the external storage.
Suppose you have a bucket named 'mytest' and a folder named 'petsFolder' created using the Storage Provider API, and use StorageAPI.GetDirectory(). Here is a list of the output of each method:
Method |
Returns |
GetName |
petsFolder |
GetAbsoluteName |
mytest:\petsFolder\ |
Refer to Storage Provider API for related sample code.
Mapped Drives and Network Drives are not supported in web environments
When a property or method is used to assign a file's path do not use user's inputs concatenations or sanitize the user's entries to avoid path traversal or path manipulation vulnerability risks.