Access Denied to a folder created by the script

1 visualización (últimos 30 días)
SOUKAINA JAAFARI
SOUKAINA JAAFARI el 21 de Ag. de 2025
Comentada: SOUKAINA JAAFARI el 7 de Sept. de 2025
Hello Everyone-
I am not an expert on Matlab but I am trying to validate some theoritical results using it as an interface of OpenEMS. I keep getting an error of denied access to a folder created by the script itself. I have tried running Matlab as an Admin and deletingt he folder and renaming it and even changing directories. I am kind of stuck and confused about the reason behind this error. Please see part of the code below and error. Thank you very much!
this is the part of the code in which I create the fodler:
%% Path
Sim_Name = ['Sim_DOA_', num2str(a), 'deg']; % e.g., Sim_DOA_-60deg
Sim_Folder = fullfile('C:\Users\HP\Documents\MATLAB\Simulations', Sim_Name);
Sim_CSX = 'geometry.xml'; % geometry file name
% Create the folder if it doesn't exist
if ~exist(Sim_Folder, 'dir')
mkdir(Sim_Folder);
end
WriteOpenEMS(Sim_Folder, FDTD, CSX);
RunOpenEMS(Sim_Folder, Sim_CSX);
and this is the error:
Error using xmlwrite>xmlWriteHelper (line 152)
Java exception occurred:
java.io.FileNotFoundException: C:\Users\HP\Documents\MATLAB\Simulations\Sim_DOA_-60deg (Access is
denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
Error in xmlwrite (line 78)
xmlWriteHelper(result,source,varargin{1});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in struct_2_xml (line 11)
xmlwrite(xmlFileName,docNode);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in WriteOpenEMS (line 19)
struct_2_xml(filename,openEMS,'openEMS');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in OpenEMSDOAVALIDATION (line 85)
WriteOpenEMS(Sim_Folder, FDTD, CSX);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Respuestas (1)

Torsten
Torsten el 21 de Ag. de 2025
Editada: Torsten el 21 de Ag. de 2025
You create
C:\Users\HP\Documents\MATLAB\Simulations\Sim_DOA_-60deg
as a folder.
But
WriteOpenEMS(Sim_Folder, FDTD, CSX);
assumes that
C:\Users\HP\Documents\MATLAB\Simulations\Sim_DOA_-60deg
is a filename.
So you try to write to a folder instead of a file which gives an error.
At least that's what I suspect is the problem.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by