RunMat
GitHub

pwd — Return the absolute path to the folder where RunMat is currently executing.

pwd returns the absolute path of the folder where RunMat is executing. The result is a character row vector (1×N) so existing MATLAB code that expects traditional character output keeps working.

How pwd works in RunMat

  • Always returns the current working folder of the RunMat process.
  • Output is a character vector using the platform-native path separators.
  • Does not accept any input arguments; if arguments are provided, MATLAB raises an error. RunMat follows the same rule by reporting pwd: too many input arguments.
  • Errors if RunMat is unable to query the current folder from the operating system.
  • Designed to cooperate with cd so workflows like start = pwd; cd("subfolder"); ...; cd(start); behave exactly as they do in MATLAB.

How pwd runs on the GPU

pwd never runs on the GPU. It performs a host-side query of the process working directory and returns the result as a character vector. The builtin registers a CPU-only GPU spec with ResidencyPolicy::GatherImmediately, ensuring fusion plans always surface the path on the host. Because there are no inputs, nothing is gathered from device memory and acceleration providers do not need to implement any hooks for this builtin.

GPU memory and residency

No. pwd always operates on the CPU. Even in scripts that perform extensive GPU computation, you can call pwd at any time to confirm the working folder without affecting GPU residency or triggering device transfers.

Examples

Show The Current Working Folder

current = pwd;
disp(current)

Expected output:

/

Capture The Folder Before Changing Directories

startDir = pwd;
if ~exist("results", "dir")
    mkdir("results");
end
cd("results");
% ... produce artifacts in results/ ...
cd(startDir)

Expected output:

% Restores the original folder after work completes

Combine pwd With cd To Print Relative Paths

old = cd("..");
fprintf("Now working in: %s\n", pwd);
cd(old)

Expected output:

% Prints the absolute path to the parent directory, then returns to the old folder
% For example:
%   Now working in: /home

Confirm The Folder Inside Scripts

fprintf("Script started in %s\n", pwd)

Expected output:

% Example output:
%   Script started in /

Log The Working Folder Together With Results

logFile = "run.log";
fid = fopen(logFile, "w");
fprintf(fid, "Working folder: %s\n", pwd);
fclose(fid)

Expected output:

% The log file contains a line such as:
%   Working folder: /

Handle Errors When The Working Folder Is Unavailable

try
    location = pwd;
catch err
    disp(err.message);
end

Expected output:

% Displays a descriptive error message if RunMat cannot query the folder,
% for example:
%   pwd: unable to determine current directory (Permission denied)

FAQ

Why does pwd return a character vector instead of a string?

MATLAB historically returns character vectors for pwd. RunMat mirrors that behavior so existing code keeps working. Use string(pwd) if you prefer string scalars.

Does pwd reflect changes made with cd?

Yes. Any successful cd call immediately affects what pwd returns, matching MATLAB's semantics.

Can pwd fail?

It is rare, but the operating system can prevent the process from querying the current folder. In that case RunMat raises an error that includes the OS reason.

Does pwd normalize the path?

RunMat returns the operating-system path exactly as reported, just like MATLAB.

Is pwd safe to call from GPU-heavy scripts?

Absolutely. The builtin does not allocate GPU memory or trigger device operations.

These functions work well alongside pwd. Each page has runnable examples you can try in the browser.

cd, addpath, copyfile, delete, dir, exist, fullfile, genpath, getenv, ls, mkdir, movefile, path, rmdir, rmpath, savepath, setenv, tempdir, tempname

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how pwd works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.