IO

◷ Reading Time: 9 minutes

IO operations allow you to read/write files from local and network files, or create folders and access current directories.

fileWrite

Creates a new file, writes the specified content to the file, and then closes the file. If the target file already exists, it is overwritten.

 fileWrite (path, content)
  • path (String): Path including the file name (Mandatory)
  • content: File content (Mandatory)
Example: fileWrite ('C:\\Users\\Alex\\Documents\\Test File.txt', 1234)
Result: Creates a file named Test File.txt in the given path with the content 1234. 
Example: 
content:= 'hello world'
fileWrite ('C:\\Users\\Alex\\Documents\\Test File.txt', content) 
Result: Creates a file named Test File.txt in the given path with the content hello world. 
Example: fileWrite ((pathCurrent()+ '\\' + 'NewFile.txt'),'This is file content.') 
Result: Creates a file named NewFile.txt in the current path with the content This is file content. 

pathCurrent() function is used to get the current path.

fileAppend

Opens a file, appends the specified content to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.

 fileAppend (path, content)
  • path (String): Path of the existing file including the file name (Mandatory)
  • content (String): File content to append (Mandatory)
Example: fileAppend ('C:\\Users\\Alex\\Documents\\Test File.txt', '1234')
Result: Append the content 1234 to the file Test File.txt in the given path.
Example: 
content:= 'append hello world'
fileAppend ('C:\\Users\\Alex\\Documents\\Test File.txt', content) 
Result: Append the content append hello world to the file named Test File.txt in the given path 
Example: fileAppend ((pathCurrent()+ '\\' + 'NewFile.txt'),'Append this content') 
Result: Append the content Append this content to the file named NewFile.txt in the current path. 

pathCurrent() function is used to get the current path.

fileReadText

Opens a text file, reads all lines of the file, and then closes the file.

 fileReadText (path)
  • path (String): Path of the existing file including the file name (Mandatory)
Example: fileReadText ('C:\\Users\\Alex\\Documents\\CurrentNumber.txt')
Result: 1234

Read the content of the file CurrentNumber.txt in the given path.
Example: fileReadText ('C:\\Users\\Alex\\Documents\\Test File.txt') 
Result: hello world

Read the content of the file Test File.txt in the given path 
Example: fileReadText (pathCurrent()+ '\\' + 'NewFile.txt') 
Result: This is file content.

Read the content of the file NewFile.txt in the current path. 
pathCurrent() function is used to get the current path.

fileReadBytes

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

 fileReadBytes (path)
  • path (String): Path of the existing file including the file name (Mandatory)
Example: fileReadBytes ('C:\\Users\\Alex\\Documents\\ByteFile.bin')
Result: 
[
     1,
     0,
     0,
     0,
     120
]

Returns a byte array of the file content.

fileExists

Determines whether the specified file exists. It returns a boolean value.

 fileExists (path)
  • path (String): Path of the file including the file name to be checked (Mandatory)
Example: fileExists ('C:\\Users\\Alex\\Documents\\Test File.txt') 
Result: True/ False

If the file Test File.txt exists in the given path, it will return true. Otherwise, false. 
Example: fileExists (pathCurrent()+ '\\' + 'NewFile.txt') 
Result: True/ Flse

If the file NewFile.txt exists in the current path, it will return true. Otherwise, false. 
pathCurrent() function is used to get the current path. 

fileDelete

Deletes a file.

 fileDelete (path)
  • path (String): Path of the file including the file name to be deleted (Mandatory)
Example: fileDelete ('C:\\Users\\Alex\\Documents\\Test File.txt') 
Result: Deletes the file Test File.txt in the given path.
Example: fileDelete (pathCurrent()+ '\\' + 'NewFile.txt') 
Result: Deletes the file NewFile.txt in the current path.

pathCurrent() function is used to get the current path. 

pathExists

Determines whether the given path refers to an existing directory on disk.

 pathExists (path)
  • path (String): Path of the file including the file name to be deleted (Mandatory)
Example: pathExists ('C:\\Users\\Alex\\Documents') 
Result: True/ False

If the given path exists, it will return true. Otherwise, false.  
Example: pathExists (pathCurrent()+ '\\New Folder') 
Result: True/ False

If New Folder exists in the current path, it will return true. Otherwise, false.   

pathCurrent() function is used to get the current path. 

pathCreate

Creates a folder based on the path. If any internal folders do not exist, it creates them as well.

 pathCreate (path)
  • path (String): Path to be created (Mandatory)
Example: pathCreate ('C:\\Users\\Alex\\Documents\\New Applications') 
Result: Creates the given path.  
Example: pathCreate (pathCurrent() + '\\File Folder') 
Result: Creates a folder called File Folder in the current path.   

pathCurrent() function is used to get the current path. 

fileTemp

Creates a zero size file at a temp directory and returns the full path.

 fileTemp ()
Example: fileTemp () 
Result: C:\Users\Alex\AppData\Local\Temp\tmp4B8A.tmp

pathCurrent

Gets or sets the fully qualified path of the current working directory.

 pathCurrent (path)
  • path (String): When it is set, it will update the current path (Optional)
Example: pathCurrent() 
Result: C:\Users\Alex\AppData\Local\Programs\Pliant Framework\FlexRule Designer\8.2.19\Bin

Return the current path.
Example: pathCurrent ('C:\\Users\\Alex\\Documents\\New Applications') 
Result: C:\Users\Alex\Documents\New Applications

Sets the current path to the given path.

pathCombine

Combines two strings into a path. This will not create a path according to the given path. It will only combine the string values in the form of a path.

 pathCombine (path1, path2, ...)
  • path1, path2,… (String): List of strings to concatenate as a single path (Mandatory)
Example: pathCombine ('C:', 'Users', 'Alex', 'Documents', 'New Applications') 
Result: C:\Users\Alex\Documents\New Applications
Example: pathCreate (pathCurrent() + 'File Folder') 
Result: C:\Users\Documents\New Applications\File Folder

Shows a path including a folder called File Folder in the current path.   

pathCurrent() function is used to get the current path.  

pathTemp

Gets a new temp directory fully qualified path which ends with \ character. The returned folder exists and is empty.

 pathTemp ()
Example: pathTemp () 
Result: C:\Users\Alex\AppData\Local\Temp\0afc57ce8a1c4064bbc68afeb7f822c7\

pathFullDirectory

Returns the absolute path for the specified path string. It concatenates the given path/ filename at the end of the current path and returns the full path.

 pathFullDirectory (path)
  • path (String): Path or file to get the full path (Mandatory)
Example: pathFullDirectory ('New Applications') 
Result: C:\Users\Alex\Documents\New Applications

pathList

Returns the list of files and folders on a specific directory based on a path.

 pathList (path, type, includeSubDirectories, pattern)
  • path (String): A path to query for a particular item i.e. file or folder or both (Mandatory)
  • type (String): specifies what type should be included in the list (Optional)
    • file: Include files
    • folder: Include folders
  • includeSubDirectories (Boolean): a boolean value (true or false) that specifies whether the search operation should include all sub-directories or only the current path’s directory (Optional)
  • pattern (String): This can contain a combination of valid literal and wildcard characters (Optional)
This is the sample folder structure:

D:
 \---Users Folder
     |   New text file.txt
     |   
     \---New Folder
         \---App Data Folder
             |   App data file.txt
             |   image file.png
             |   
             \---Programs Folder
Example: pathList('D:\\Users Folder')
Result:
[
     "D:\Users Folder\New text file.txt",
     "D:\Users Folder\New Folder"
]

List all folders and files in the given location, and includes items only on the top folder.
Example: pathList('D:\\Users Folder', 'file, folder', true) 
Result:
[
     "D:\Users Folder\New text file.txt",
     "D:\Users Folder\New Folder\App Data Folder\App data file.txt",
     "D:\Users Folder\New Folder\App Data Folder\image file.png",
     "D:\Users Folder\New Folder",
     "D:\Users Folder\New Folder\App Data Folder",
     "D:\Users Folder\New Folder\App Data Folder\Programs Folder"
]

List all files and folders in the given location, and including all items at all the levels.
Example: pathList('D:\\Users Folder', 'file', true, '*.png') 
Result:
[
     "D:\Users Folder\New Folder\App Data Folder\image file.png"
]

List all files with the extension .png in the given location, at all the levels.
Example: pathList('D:\\Users Folder', 'file', true, '*.png') 
Result: []

List all files with the extension .png in the given location, at the top level.
Updated on January 13, 2021

Was this article helpful?

Related Articles