1. Home
  2. Docs
  3. UniREST Solution 3.5
  4. UniREST Client
  5. Online Files
  6. File Manager

File Manager

The UniRESTClient.Async.FileManager class (available from the 3.2 version) contains a set of methods for performing some common file management operations. These operations are performed on online files, both created with the File class and uploaded.


Instantiate a FileManager object

The first thing to do is simply to declare an instance of the UniRESTClient.Async.FileManager. With this single instance you can perform all the available file management operations.

§var§ myFileManager = §new§ #UniRESTClient.Async#.$FileManager$();


TargetRoot

All the various file operations require the TargetRoot parameter. This predefined parameter specifies where the online file or working folder are located. Four locations are available:

UserFilesFolderThis is the user’s dedicated root folder where the files created by the File class are stored.
UserUploadsFolderThis is the user’s dedicated root folder where all the uploaded files are stored.
GameFilesFolderThis is the Game’s dedicated root folder where the files created by the File class are stored.
GameUploadsFolderThis is the Game’s dedicated root folder where all the uploaded files are stored.

Delete()

The Delete() method deletes an online file.

myFileManager.$Delete$(%target, fileName, callBack%);

target|TagetRoot
The root folder in which to perform this operation.
__
fileName|string
The name of the file the operation has to be performed.
If the file is under subfolders, this string must contain the path too.
__
callBack|Action<bool>
The function to call on operation completed.

bool
true if the operation is completed, false in case of error.

In case of error, the Error string property will contain an “error code”:
FILE_NOT_DELETED = the file can’t be deleted;
FILE_NOT_EXISTING = the file doesn’t exist;
COMMUNICATION_ERROR = a communication error with the Server occurs.

_ = myFileManager.Delete(
    UniRESTClient.TargetRoot.UserFileFolder,
    "myassets/model.fbx",
    (bool ok) => { . . . }
);

Rename()

The Rename() method changes the name of an online file.

myFileManager.$Rename$(%target, fileName, newName, callBack%);

target|TagetRoot
The root folder in which to perform this operation.
__
fileName|string
The name of the file the operation has to be performed.
If the file is under subfolders, this string must contain the path too.
__
newName|string
The new name for this file.
If the original file is under subfolders, this string must contain the same path too.
__
callBack|Action<bool>
The function to call on operation completed.

bool
true if the operation is completed, false in case of error.

In case of error, the Error string property will contain an “error code”:
FILE_NOT_RENAMED = the file can’t be renamed;
FILE_NOT_EXISTING = the file doesn’t exist;
COMMUNICATION_ERROR = a communication error with the Server occurs.

_ = myFileManager.Rename(
    UniRESTClient.TargetRoot.UserFileFolder,
    "myassets/model.fbx",
    "myassets/player_model.fbx"
    (bool ok) => { . . . }
);

Exists()

The Exists() method checks if an online file exists.

myFileManager.$Exists$(%target, fileName, callBack%);

target|TagetRoot
The root folder in which to perform this operation.
__
fileName|string
The name of the file the operation has to be performed.
If the file is under subfolders, this string must contain the path too.
__
callBack|Action<bool>
The function to call on operation completed.

bool
true if the file exists, false if the file doesn’t exist or an error occurred.

In case of error, the Error string property will contain an “error code”:
FILE_NOT_EXISTING = the file doesn’t exist;
COMMUNICATION_ERROR = a communication error with the Server occurs.

_ = myFileManager.Exists(
    UniRESTClient.TargetRoot.UserFileFolder,
    "myassets/model.fbx",
    (bool exists) => { . . . }
);

Size()

The Size() method returns the online file size in bytes.

myFileManager.$Size$(%target, fileName, callBack%);

target|TagetRoot
The root folder in which to perform this operation.
__
fileName|string
The name of the file the operation has to be performed.
If the file is under subfolders, this string must contain the path too.
__
callBack|Action<long>
The function to call on operation completed.

long
the number of bytes of the file size or 0 if an error occurred.

In case of error, the Error string property will contain an “error code”:
FILE_NOT_EXISTING = the file doesn’t exist;
COMMUNICATION_ERROR = a communication error with the Server occurs.

_ = myFileManager.Size(
    UniRESTClient.TargetRoot.UserFileFolder,
    "myassets/model.fbx",
    (long size) => { . . . }
);

List()

The List() method returns all the files starting from the given root or subfolder and including existing subfolders.

myFileManager.$List$(%target, path, callBack%);

target|TagetRoot
The root folder in which to perform this operation.
__
path|string
An empty string if the files scan has to be performed in the given root folder or a path if the scan has to start from the given subfolder.
__
callBack|Action<string[]>
The function to call on operation completed.

string[]
a string array containing all the found files or an 0 length array if nothing is found or an error occurred.

In case of error, the Error string property will contain an “error code”:
COMMUNICATION_ERROR = a communication error with the Server occurs.

_ = myFileManager.List(
    UniRESTClient.TargetRoot.UserFileFolder,
    "myassets/",
    (string[] filesList) => { . . . }
);

Note about the GameUploadsFolder

While the created files are stored inside a predefined folder named files, the uploaded files are stored directly in the root of the Game Uploads folder. This means that the List() method, when used with the GameUploadsFolder, will list the file folder too, including the created files. Instead, this doesn’t happen with the User‘s dedicated folders.