Recents
File data typeOfficial Content

File is a GeneXus data type that allows you to manage system files. It makes it easier to develop applications that need to execute actions that affect system files.

The File data type enables system file management. It can be used for typical operations such as copying, moving, renaming and deleting files. You can also use File data type to get file attributes such as modification, date, time and size.

Properties#

Source Assign a path to the file. The source cannot be read, use GetAbsoluteName(*) instead.
Separator Returns the name separator character depending on the OS.
ErrCode Returns the result of the last operation.
ErrDescription Returns the result description of the last operation.

 

Methods#

Copy Copies the specified file to a new file.
Delete Deletes the specified file.
Exists Determines whether the specified file exists.
GetName Returns the name of the specified file.
(*)GetAbsoluteName Returns the full path name of the specified file.
GetPath Returns the path of the parent directory.
Rename Renames the specified file.
GetLastModified Returns the date and time the specified file was last modified.
GetLength Gets the size of the specified file.
Open see more details
Close see more details

 

Copy#

Copies the file specified in source to a new location. If the target file already exists, it will be overridden.

Parameters#

New filename (Character)

Example#

&file.copy("c:\empcopiedFile.txt")

Delete#

Deletes the file specified in source.

Example#

&file.delete()

Exists#

Checks whether the file specified in source exists

Returned values#

Boolean

Example#

If &file.exists()
    msg("The file exists!")
Else 
    msg("The file does not exist!")
EndIf

GetName#

Returns the name of the file specified in source.

Returned values#

Character

Example#

&file.Source="c:\myFile.txt"
Msg(&file.GetName()) // screen shows: myFile.txt

GetAbsoluteName#

Return the absolute name of the file specified in source.

Returned values#

Character

Example#

&file.Source="c:\empmyFile.txt"
Msg(&file.GetAbsoluteName()) // screen shows: c:\empmyFile.txt

GetPath#

Returns the path of the parent directory.

Returned values#

Character

Example#

&parentDir = &file.getPath()

Rename#

Renames the file specified in source. It can also be used to move the file, changing its current path.

Parameters#

New name of the file (Character)

Example#

&file.Rename("d:\empnewFileName.txt")

GetLastModified#

Returns the date and time the file specified in source was last modified.

Rerturned values#

DateTime

Example#

&dateTime = &file.GetLastModified()

GetLength#

Returns the size (in bytes) of the file specified in source.

Returned values#

Numeric

Example#

&size = &file.GetLength()

Error Codes#

0 Operation completed successfully.
1 Invalid file instance - if source property was not set.
2 File does not exist.
3 File already exists.
100 Security error.
-1 Undefined error.

See Also#

File data type: Text file handling

Scope#

Language Java, .NET,  Ruby
Objects Procedure object, Web Panel object, Transaction object
   




Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.