File

File object. Use it to perform actions not related to a particular object. You do not need to record or learn this object, it is always automatically available in any test.

Action Summary

Action Description
Append Appends text to a file.
CreateFolder Creates a folder.
Delete Deletes a file.
DeleteFolder Deletes a folder.
Exists Checks if file exists or not.
Find

Find files in folder using wildcard pattern (including * and ?).

FolderExists Checks if folder exists.
FolderInfo Gets information about a folder.
Include Includes code from a file.
IncludeOnce Includes code from a file if it was not included earlier.
Info Gets information about a file.
Read Reads text file.
ResolvePath Finds the file in test folders and calculates its absolute path.
Touch Sets file modification time to current time.
Write Writes text file.

Action Detail

Append(fileName, text)

Appends text to a file.

Parameters:

Name Type Description
fileName string Name of the file.
text string Text to append to the file.

CreateFolder(folderPath)

Creates a folder.

Parameters:

Name Type Description
folderPath string Path to a folder.

Delete(fileName)

Deletes a file.

Parameters:

Name Type Description
fileName string Name of the file to delete.

DeleteFolder(folderPath)

Deletes a folder.

Parameters:

Name Type Description
folderPath string Path to a folder.

Exists(fileName)

Checks if file exists or not.

Parameters:

Name Type Description
fileName string Name of the file to check.

Returns:

true if file exists, false otherwise.

Find(path, searchPattern=*, recursive, firstOnly, files, folders)

Find files in folder using wildcard pattern (including * and ?).

I.e. File.Find("c:/Temp", "*.txt", true) may return
  C:\Temp\file1.txt
  C:\Temp\SubFolder\file2.txt
  C:\Temp\SubFolder2\file3.txt
  C:\Temp\SubFolder2\file4.txt

Result may be converted to array like that:
var arrFiles = File.Find("c:/Temp", "*.txt", true).split('\n');

Parameters:

Name Type Description
path string Path to a folder to search in.
searchPattern=* string Search pattern (may include * and ? wildcards, but no regexp).
recursive boolean 'true' for folder and subfolders.
Optional, Default: false.
firstOnly boolean Return only first matching item (if any).
Optional, Default: false.
files boolean Return matching files.
Optional, Default: true.
folders boolean Return matching folders.
Optional, Default: false.

Returns:

string: \n-separated string where each line is a path to the found item.

FolderExists(folderPath)

Checks if folder exists.

Parameters:

Name Type Description
folderPath string Path to a folder.

Returns:

true if folder exists, false - otherwise.

FolderInfo(folderPath)

Gets information about a folder.

Parameters:

Name Type Description
folderPath string Path to a folder.

Returns:

Folder object as described here https://msdn.microsoft.com/en-us/library/1c87day3%28v=vs.84%29.aspx e.g. Path, SubFolders and Files enumeration.

Include(fileName)

Includes code from a file. Normally used together with eval statement, i.e.: eval( File.Include('myfile.js') )

Parameters:

Name Type Description
fileName string Name of the file to load.

Returns:

Contents of the source file for evaluation.

IncludeOnce(fileName)

Includes code from a file if it was not included earlier. Normally used together with eval statement, i.e.: eval( File.IncludeOnce('myfile.js') )

Parameters:

Name Type Description
fileName string Name of the file to load.

Returns:

Contents of the source file for evaluation.

Info(fileName)

Gets information about a file.

Parameters:

Name Type Description
fileName string Name of the file.

Returns:

File object as described here https://msdn.microsoft.com/en-us/library/1ft05taf%28v=vs.84%29.aspx e.g. DateLastModified, Size, Type, Name, Path.

Read(fileName)

Reads text file.

Parameters:

Name Type Description
fileName string Name of the file to read.

Returns:

Contents of the text file as string.

ResolvePath(fileName)

Finds the file in test folders and calculates its absolute path.

Parameters:

Name Type Description
fileName string Name of the file to resolve path.

Returns:

Absolute path of the file.

Touch(fileName)

Sets file modification time to current time.

Parameters:

Name Type Description
fileName string Name of the file to touch.

Write(fileName, text)

Writes text file.

Parameters:

Name Type Description
fileName string Name of the file to write.
text string Text to write into the file.