Skip to content

3.10 ControllerFileManager Class

Overview

ControllerFileManager handles controller file upload, download, deletion, search, and existence checks.

3.10.1 Upload File

cpp
Upload(const std::string& filePath, const std::string& fileType, bool overwriting = false)
ItemDescription
PurposeUpload a local file to the corresponding controller file area
filePathLocal file path. User programs, block programs, and similar file groups are resolved by base file name
fileTypeFile type. Prefer the constants in FileType
overwritingWhether to allow overwriting a controller-side file with the same name
ReturnSTATUS_CODE

The file type changes how the upload is performed:

File TypeUpload Rule
FileType::TRAJECTORYUploads the .trajectory file by base name
FileType::USER_PROGRAMUploads the .json and .xml files by base name
FileType::BLOCK_PROGRAMUploads the .block , .json , and .xml files by base name
FileType::ROBOT_TMP / FileType::TRAJECTORY_CSVUploads the single file passed by name

3.10.2 Download File

cpp
Download(const std::string& fileName, const std::string& localPath, const std::string& fileType, bool overwriting = false)
ItemDescription
PurposeDownload a controller file to a local directory or target file
fileNameController-side file name or base name. User programs and block programs do not need an extension
localPathLocal save directory. For FileType::FLY_SHOT , this is treated as a target file path
fileTypeFile type. Prefer the constants in FileType
overwritingWhen false , returns FAILED_TO_DOWNLOAD_SAME_NAME_FILE if the local target already exists
ReturnSTATUS_CODE

Additional rules:

  • When downloading a user program or block program, the SDK downloads the related files and creates a same-name .zip locally.
  • Before downloading, the SDK checks whether the controller-side target exists. If it does not exist, FILE_NOTEXIST is returned.

3.10.3 Delete File

cpp
Delete(const std::string& fileName, const std::string& fileType)
ItemDescription
PurposeDelete a controller-side file or file group
fileNameController-side file name or base name
fileTypeFile type, which determines whether a single file or a same-name file group is deleted
ReturnSTATUS_CODE

The target is checked before deletion. If it does not exist, FILE_NOTEXIST is returned.

3.10.4 Search File

cpp
Search(const std::string& pattern)
ItemDescription
PurposeSearch common controller file areas by file name pattern
patternGlob-style pattern, such as *.csv or demo*
Returnstd::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

cpp
IsExist(const std::string& fileName)
ItemDescription
PurposeCheck whether an absolute controller-side path exists
fileNameAbsolute controller-side path, for example /root/robot_data/progs/robot_tmp/demo.csv
Returnstd::pair<bool, STATUS_CODE>

STATUS_CODE::OK means the check itself succeeded; the bool value indicates whether the file exists.

Minimal Call Example

cpp
#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

cpp
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

cpp
// 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

cpp
// STATUS_CODE deleteRet = arm.file_manager.Delete("demo.csv", FileType::TRAJECTORY_CSV);

Example code:

cpp17/file_manager_basic/src/main.cpp
cpp
#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();
}