3.10 ControllerFileManager Class
Overview
ControllerFileManager handles controller file upload, download, deletion, search, and existence checks.
3.10.1 Upload File
Upload(const std::string& filePath, const std::string& fileType, bool overwriting = false)| Item | Description |
|---|---|
| Purpose | Upload a local file to the corresponding controller file area |
filePath | Local file path. User programs, block programs, and similar file groups are resolved by base file name |
fileType | File type. Prefer the constants in FileType |
overwriting | Whether to allow overwriting a controller-side file with the same name |
| Return | STATUS_CODE |
The file type changes how the upload is performed:
| File Type | Upload Rule |
|---|---|
FileType::TRAJECTORY | Uploads the .trajectory file by base name |
FileType::USER_PROGRAM | Uploads the .json and .xml files by base name |
FileType::BLOCK_PROGRAM | Uploads the .block , .json , and .xml files by base name |
FileType::ROBOT_TMP / FileType::TRAJECTORY_CSV | Uploads the single file passed by name |
3.10.2 Download File
Download(const std::string& fileName, const std::string& localPath, const std::string& fileType, bool overwriting = false)| Item | Description |
|---|---|
| Purpose | Download a controller file to a local directory or target file |
fileName | Controller-side file name or base name. User programs and block programs do not need an extension |
localPath | Local save directory. For FileType::FLY_SHOT , this is treated as a target file path |
fileType | File type. Prefer the constants in FileType |
overwriting | When false , returns FAILED_TO_DOWNLOAD_SAME_NAME_FILE if the local target already exists |
| Return | STATUS_CODE |
Additional rules:
- When downloading a user program or block program, the SDK downloads the related files and creates a same-name
.ziplocally. - Before downloading, the SDK checks whether the controller-side target exists. If it does not exist,
FILE_NOTEXISTis returned.
3.10.3 Delete File
Delete(const std::string& fileName, const std::string& fileType)| Item | Description |
|---|---|
| Purpose | Delete a controller-side file or file group |
fileName | Controller-side file name or base name |
fileType | File type, which determines whether a single file or a same-name file group is deleted |
| Return | STATUS_CODE |
The target is checked before deletion. If it does not exist, FILE_NOTEXIST is returned.
3.10.4 Search File
Search(const std::string& pattern)| Item | Description |
|---|---|
| Purpose | Search common controller file areas by file name pattern |
pattern | Glob-style pattern, such as *.csv or demo* |
| Return | std::pair<std::vector<FileInfo>, STATUS_CODE> |
Returned FileInfo records contain the file name and its path. Use the status code to determine whether the call succeeded; the result list may be empty.
3.10.5 Check Whether a File Exists
IsExist(const std::string& fileName)| Item | Description |
|---|---|
| Purpose | Check whether an absolute controller-side path exists |
fileName | Absolute controller-side path, for example /root/robot_data/progs/robot_tmp/demo.csv |
| Return | std::pair<bool, STATUS_CODE> |
STATUS_CODE::OK means the check itself succeeded; the bool value indicates whether the file exists.
Minimal Call Example
#include <iostream> // Standard output stream for printing file query results
#include "arm_api.h" // Arm entry point; after connection, file APIs are accessed through arm.file_manager
#include "status_code.h" // STATUS_CODE for checking SDK call results
int main()
{
Arm arm;
STATUS_CODE connectRet = arm.Connect("192.168.110.2", "");
if (connectRet != STATUS_CODE::OK) {
return 1;
}
auto [items, searchRet] = arm.file_manager.Search("*.csv");
auto [exists, existRet] = arm.file_manager.IsExist(
"/root/robot_data/progs/robot_tmp/demo.csv"
);
if (searchRet != STATUS_CODE::OK || existRet != STATUS_CODE::OK) {
return 1;
}
std::cout << "search_count=" << items.size() << "\n";
std::cout << "demo_exists=" << exists << "\n";
// arm.file_manager.Download(
// "demo.csv",
// "D:/sdk-demo",
// FileType::TRAJECTORY_CSV,
// true
// );
return 0;
}Scenario Examples
The snippets below cover the APIs on this page across search, existence checks, upload/download, and deletion. They assume the arm object from the minimal example is already connected. Calls that write or delete files remain commented out; confirm the paths before running them.
Search and Check File Existence
auto [items, searchRet] = arm.file_manager.Search("*.csv");
auto [exists, existRet] = arm.file_manager.IsExist("/root/robot_data/progs/robot_tmp/demo.csv");
if (searchRet == STATUS_CODE::OK && existRet == STATUS_CODE::OK) {
std::cout << "search_count=" << items.size() << " exists=" << exists << "\n";
}Upload and Download Files
// STATUS_CODE uploadRet = arm.file_manager.Upload("D:/sdk-demo/demo.csv", FileType::TRAJECTORY_CSV, true);
// STATUS_CODE downloadRet = arm.file_manager.Download("demo.csv", "D:/sdk-demo", FileType::TRAJECTORY_CSV, true);Delete a Controller-Side File
// STATUS_CODE deleteRet = arm.file_manager.Delete("demo.csv", FileType::TRAJECTORY_CSV);Example code:
#include "query_files/run.h"
#include "write_files/run.h"
int main(void)
{
// [ZH] 默认只调用一个门面方法;如需体验其他接口,请把下一行替换成下面任意一行。
// [EN] The main function calls only one facade by default. Replace the next line with any line below to try other APIs.
return RunFileManagerBasicQueryFiles();
// return RunFileManagerBasicWriteFiles();
}