81. FileUtils

Module for getting information about files and directories. Their types and sizes and functions for checking, creating and removing them.

81.1. Authors

  • Lukas Ocilka <lukas.ocilka@suse.cz>

81.2. Summary of Module Globals

List of Global Functions

  • CheckAndCreatePath - Checks whether the path (directory) exists and return a boolean value whether everything is OK or user accepted the behavior as despite some errors. If the directory doesn't exist, it offers to create it (and eventually creates it).

  • Exists - Function which determines if the requested file/directory exists.

  • GetFileRealType - Function returns the real type of requested file/directory. If the file is a link to any object, "link" is returned.

  • GetFileType - Function returns the type of requested file/directory. If the file is a link to any object, the object's type is returned.

  • GetOwnerGroupID - Function which determines the owner's group ID of requested file/directory.

  • GetOwnerUserID - Function which determines the owner's user ID of requested file/directory.

  • GetSize - Function which returns the size of requested file/directory.

  • IsBlock - Function which determines if the requested file/directory is a block file (device) or link to a block device.

  • IsCharacterDevice - Function which determines if the requested file/directory is a character device or link to a character device.

  • IsDirectory - Function which determines if the requested file/directory is a directory or it is a link to a directory.

  • IsFifo - Function which determines if the requested file/directory is a fifo or link to a fifo.

  • IsFile - Function which determines if the requested file/directory is a regular file or it is a link to a regular file.

  • IsLink - Function which determines if the requested file/directory is a link.

  • IsSocket - Function which determines if the requested file/directory is a socket or link to a socket.

  • MD5sum - Function return the MD5 sum of the file.

List of Global Variables

    81.3. Global Functions

    81.3.1. CheckAndCreatePath

    Checks whether the path (directory) exists and return a boolean value whether everything is OK or user accepted the behavior as despite some errors. If the directory doesn't exist, it offers to create it (and eventually creates it).

    Function parameters

    • string pathvalue

    Return value

    • boolean - whether everything was OK or whether user decided to ignore eventual errors

    81.3.2. Exists

    Function which determines if the requested file/directory exists.

    Function parameters

    • string target

    Return value

    • boolean - true if exists

    Example 4. 

    	FileUtils::Exists ("/tmp") -> true
    	FileUtils::Exists ("/tmp/somefile") -> false


    81.3.3. GetFileRealType

    Function returns the real type of requested file/directory. If the file is a link to any object, "link" is returned.

    Function parameters

    • string target

    Return value

    • string - file type (directory|regular|block|fifo|link|socket|chr_device), nil if doesn't exist

    Example 5. 

    	FileUtils::GetFileRealType ("/var") -> "directory"
    	FileUtils::GetFileRealType ("/etc/passwd") -> "file"
    	FileUtils::GetFileRealType ("/does-not-exist") -> nil


    81.3.4. GetFileType

    Function returns the type of requested file/directory. If the file is a link to any object, the object's type is returned.

    Function parameters

    • string target

    Return value

    • string - fle type (directory|regular|block|fifo|link|socket|chr_device), nil if doesn't exist

    81.3.5. GetOwnerGroupID

    Function which determines the owner's group ID of requested file/directory.

    Function parameters

    • string target

    Return value

    • integer - GID, nil if doesn't exist

    Example 6. 

    	FileUtils::GetOwnerGroupID ("/etc/passwd") -> 0
    	FileUtils::GetOwnerGroupID ("/does-not-exist") -> nil


    81.3.6. GetOwnerUserID

    Function which determines the owner's user ID of requested file/directory.

    Function parameters

    • string target

    Return value

    • integer - UID, nil if doesn't exist

    Example 7. 

    	FileUtils::GetOwnerUserID ("/etc/passwd") -> 0
    	FileUtils::GetOwnerUserID ("/does-not-exist") -> nil


    81.3.7. GetSize

    Function which returns the size of requested file/directory.

    Function parameters

    • string target

    Return value

    • integer - file size, -1 if doesn't exist

    Example 8. 

    	FileUtils::GetSize ("/var/log/YaST2") -> 12348
    	FileUtils::GetSize ("/does-not-exist") -> -1


    81.3.8. IsBlock

    Function which determines if the requested file/directory is a block file (device) or link to a block device.

    Function parameters

    • string target

    Return value

    • boolean - true if it is a block file, nil if doesn't exist

    Example 9. 

    	FileUtils::IsBlock ("/var") -> false
    	FileUtils::IsBlock ("/dev/sda2") -> true
    	FileUtils::IsBlock ("/dev/does-not-exist") -> nil


    81.3.9. IsCharacterDevice

    Function which determines if the requested file/directory is a character device or link to a character device.

    Function parameters

    • string target

    Return value

    • boolean - true if it is a charcater device, nil if doesn't exist

    81.3.10. IsDirectory

    Function which determines if the requested file/directory is a directory or it is a link to a directory.

    Function parameters

    • string target

    Return value

    • boolean - true if it is a directory, nil if doesn't exist

    Example 10. 

    	FileUtils::IsDirectory ("/var") -> true
    	FileUtils::IsDirectory ("/var/log/messages") -> false
    	FileUtils::IsDirectory ("/does-not-exist") -> nil


    81.3.11. IsFifo

    Function which determines if the requested file/directory is a fifo or link to a fifo.

    Function parameters

    • string target

    Return value

    • boolean - true if it is a fifo, nil if doesn't exist

    81.3.12. IsFile

    Function which determines if the requested file/directory is a regular file or it is a link to a regular file.

    Function parameters

    • string target

    Return value

    • boolean - true if it is a regular file, nil if doesn't exist

    Example 11. 

    	FileUtils::IsFile ("/var") -> false
    	FileUtils::IsFile ("/var/log/messages") -> true
    	FileUtils::IsFile ("/does-not-exist") -> nil


    81.3.13. IsLink

    Function which determines if the requested file/directory is a link.

    Function parameters

    • string target

    Return value

    • boolean - true if it is a link, nil if doesn't exist

    81.3.14. IsSocket

    Function which determines if the requested file/directory is a socket or link to a socket.

    Function parameters

    • string target

    Return value

    • boolean - true if it is a socket, nil if doesn't exist

    81.3.15. MD5sum

    Function return the MD5 sum of the file.

    Function parameters

    • string target

    Return value

    • string - MD5 sum of the file, nil if doesn't exist

    Example 12. 

    	FileUtils::MD5sum ("/etc/passwd") -> "74855f6ac9bf728fccec4792d1dba828"
    	FileUtils::MD5sum ("/does-not-exist") -> nil


    81.4. Global Variables

    81.5. Module Requirements

    81.5.1. Module Imports

    • Popup
    • SCR
    • String

    81.5.2. Module Includes