Main Content

getAttachedFilesFolder

Identify folder on a worker where attached files are copied to

    Description

    folder = getAttachedFilesFolder returns the path to the folder on the current worker where attached files are copied to. Attached files are specified by the AttachedFiles of the job that the worker is currently running.

    If getAttachedFilesFolder is evaluated on a worker, folder is the path to the local folder. Otherwise, folder is an empty character vector.

    example

    folder = getAttachedFilesFolder(filename) uses filename to search for files or folders in the attached files folder.

    Attached files are specified by the AttachedFiles of the job that the worker is currently running. A match is found if a file or folder specified in the AttachedFiles property ends with filename. If a folder is specified in the AttachedFiles property, no matches can be found for any files in that folder.

    If only one file or folder matches, filename is the path to that file or folder. If multiple files or folders match, filename is a cell array containing every matching path. If filename does not match the name of an attached file or folder, folder is an empty cell array.

    Examples

    collapse all

    You can use addAttachedFiles to attach a folder to a parallel pool, then use getAttachedFilesFolder to find the folder on workers.

    Create a parallel pool with 4 workers.

    p = parpool(4);

    In this example, the current directory contains two folders myFolder1 and myFolder2, containing files myFile1.csv and myFile2.csv respectively.

    ├───myFolder1
    │       myFile1.csv
    │
    └───myFolder2
            myFile2.csv

    Use addAttachedFiles to attach the two folders to the pool.

    addAttachedFiles(p,{'myFolder1','myFolder2'});

    When you use addAttachedFiles, the folders are copied to workers. Each copied folder will have a unique name on the workers.

    Then, use getAttachedFilesFolder on the workers to get the path to the copy of 'myFolder1'. Use readtable to read the file myFile1.csv in the folder.

    parfor i = 1
        folder = getAttachedFilesFolder('myFolder1');
        filepath = fullfile(filepath, 'myFile1.csv');
        t = readtable(filepath);
    end

    Input Arguments

    collapse all

    Name of file or folder to search for in the attached files available on the current worker, specified as a string or character vector. Attached files are specified by the AttachedFiles of the job that the worker is currently running.

    Example: "myFile1.csv"

    Data Types: string | char

    Output Arguments

    collapse all

    Folder containing attached files available on the current worker, specified as a character vector or cell array.

    If filename is specified, folder is the path or paths matching filename. If only one file or folder matches, filename is the path to that file or folder. If multiple files or folders match, filename is a cell array containing every matching path. If filename does match the name of an attached file or folder, folder is an empty cell array.

    If filename is not specified, folder is the path containing attached files available to the worker.

    If getAttachedFilesFolder is not evaluated on a worker, folder is an empty character vector.

    Data Types: char | cell

    Version History

    Introduced in R2012a