Can't create/open txt files

18 visualizaciones (últimos 30 días)
Theo Y
Theo Y el 18 de Feb. de 2021
Comentada: Theo Y el 19 de Feb. de 2021
The title pretty much sums it up. I want to use fopen to create or open a file and it is just returning -1 everytime. It seems like Matlab has not the rights to do that but I don't understand why.
I am administrator, I tried running Matlab as admistrator and I know I am in the right folder.
  9 comentarios
dpb
dpb el 18 de Feb. de 2021
Indeed, looks strange.
wd='D:\Work\Stage';
[stuff,msg] = fopen(fullfile(wd,'filename.txt'),'w')
??
Theo Y
Theo Y el 18 de Feb. de 2021
Permission denied.

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 18 de Feb. de 2021
Does the file D:\Work\Stage\filename.txt exist when you try to open it for writing? What do these commands return?
filename = 'd:\Work\Stage\filename.txt'
exist(filename) % Does it exist?
fileattrib(filename) % What permissions do the various groups have to this file?
  9 comentarios
Rik
Rik el 18 de Feb. de 2021
I have heard about an issue where on a cracked version fopen would fail for file extensions that were assigned a program in Windows. The issue would magically appear and disappear, but fopen on files without a recognized extension would always work. I tried to reproduce it so I could send a bug report, but neither of us managed to find the root cause (other than presumably the crack).
So if you're running a cracked version, see if your university or the organization facilitating your internship can provide you with a valid license. (the presumption of you being a student and doing an internship being based on your folder name meaning 'internship' in Dutch)
Theo Y
Theo Y el 19 de Feb. de 2021
So I restarted my laptop and tried the initial command:
>> fopen('D:\Work\Stage\truc.txt','w')
ans =
-1
Interestingly, a popup from Avast was telling me that it blocked an action from Matlab as it tries to create files. I clicked on authorized and did it again:
>> fopen('D:\Work\Stage\truc.txt','w')
ans =
3
It worked!
Very strange to me that it was avast blocking the action all along. I didn't have any popup from Avast yesterday though. It is also very strange that avast protects only this folder from Matlab also. Why not everyone of them?
In any case, in all this strangeness, the problem is solved.
Thank you for taking time replying to me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by