Unable to write file: Read-only file system

113 次查看(过去 30 天)
I'm using the R2021a on MacOS Big Sur. I'm trying to run a script on that needs to write a file using the save command. I keep getting the following error:
Error using save
Unable to write file /Testing: Read-only file system.
The script runs the function:
save([dlocs{ii},filesep,dnames{ii}],'mov','-v7.3');
Where the first parameter are all preassigned variables and 'mov' is a temporary string variable. Testing is the filename of a .tif file.
The attributes of Testing.tif are:
archive: NaN
system: NaN
hidden: NaN
directory: 0
UserRead: 1
UserWrite: 1
UserExecute: 0
GroupRead: 1
GroupWrite: 0
GroupExecute: 0
OtherRead: 1
OtherWrite: 0
OtherExecute: 0
I have admin access to all files on the computer that I am using.
  1 个评论
Adam Decker
Adam Decker 2021-11-23
The directory attributes are
archive: NaN
system: NaN
hidden: NaN
directory: 1
UserRead: 1
UserWrite: 1
UserExecute: 1
GroupRead: 1
GroupWrite: 1
GroupExecute: 1
OtherRead: 1
OtherWrite: 1
OtherExecute: 1

请先登录,再进行评论。

回答(1 个)

Zinea
Zinea 2024-2-19
编辑:Zinea 2024-2-20
The error message "Unable to write file /Testing: Read-only file system" suggests that the script is trying to save the file to the root directory (/) of your macOS filesystem, which is typically protected and not writable by user-level processes. This could be due to an incorrect path specified in the variables dlocs{ii} and dnames{ii}.
Here are some ways to resolve the issue:
1. Check the Path Variables
The variables "dlocs{ii}" and "dnames{ii}" determine where the “save” function attempts to write the file. You need to ensure that dlocs{ii} points to a directory where you have write access. Here's how you can check and correct the path:
Print the Path: Add a line of code before the save command to print the full path to the console. This will help you verify the path being used.
fullPath = fullfile(dlocs{ii}, dnames{ii});
disp(['Attempting to save to: ', fullPath]);
Validate the Path: If the printed path is not what you expect, or if it's pointing to the root directory /, you need to adjust dlocs{ii} to point to a valid, writable directory.
2. Correct Directory Permissions
Even if the path is correct, the directory might not have the necessary write permissions. Here's how to check and modify permissions:
Using Finder: Navigate to the directory in Finder, right-click on it, and select 'Get Info'. Scroll down to 'Sharing & Permissions' and ensure that your user has 'Read & Write' access. If not, click the lock icon to make changes, and then set the appropriate permissions.
Using Terminal: Open the Terminal and use the "chmod" command to grant write access to your user. For example, to grant write access to the current user for a folder named 'MyFolder', you would use in bash:
chmod u+w /path_to_MyFolder
By following these detailed steps, you should be able to possibly diagnose and fix the issue with the save function in MATLAB. If the problem persists, double-check the values of "dlocs{ii}" and "dnames{ii}" at runtime, and ensure that your script has the necessary permissions to write to the desired location.

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by