Accessing the file system and modifying files with Xill is usually pretty easy and straightforward. Every function is included in the File package.

Moving files around
Simple modifications of the file structure can be done with the following functions:

  • File.copy(from,to)
  • File.delete(path)
  • File.createFolder(path)

They all need one or two full or relative paths as parameters. Moving can be done with a copy and delete. File.delete() works on files as well as folders.

Getting info

There are several options to gather information about files and folders. They only need the path of the folder/file as parameter:

  • File.exists(path);
  • File.canExecute(path);
  • File.canRead(path);
  • File.canWrite(path);
  • File.isHidden(path);
  • File.getMimeType(path);
  • File.getSize(path); returns filesize in bytes
  • File.iterateFiles(path); returns an iterable with all complete paths of the files in that folder.
  • File.iterateFolders(path);¬†returns an iterable with all complete paths of the folders in that folder.

Notes about iterateFiles() and iterateFolders()

These functions can be given an extra boolean parameter (the default is false), which makes the function return every descendant instead of only the direct children. And, for performance reasons, the return type is not a list but an iterable. This means that the resulting items will only be actually loaded in a foreach() loop. For more information about these variables, check the variable types or the collections tutorial.

Opening and saving files

The general functions for this are:

  • File.getText(path); returns the text from a text document
  • File.save(path); saves a string to the specified path.
  • File.appendTo(path,content); appends the string value of 'content' to the file at specified path. creates the file if it doesn't exist yet.

Running a file

It's also possible to execute a program from a robot with System.exec(arguments,directory); Example:

use System;

var temp_path = "D:/temp";
var result = System.exec(["cmd.exe", "/C", "mkdir batchtest_temp"],temp_path);
System.print(result);

This calls a command prompt at the location 'temp_path' and executes the command to create a directory. Any commandline program can be used from a robot this way, to extend the functionality of Xill endlessly.

Other file system usage

There are more functions communicating with the file system, like Excel.loadWorkbook() and Web.download(). These should all be addressed in tutorials specifically about the relevant subjects. File.extractText is also in the File package, and worth trying, but not core functionality in communicating with the file system.

If you missed anything, please click 'no' below and create a ticket. We'll get back to you quickly.