Standalone Application - fwrite invalid file identifier if launched by another user
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
I have deployed an application which asks for a csv to read data from.
The application is launched by running the .exe saved into a folder where all users can access.
If I am the person who is using that csv first, it's ok.
If another user logs in, launches the application and select the same csv which I opened before, he gets error "invalid file identifier", as if the file is still open.
In the code I always close the file once the data have been read, but something is not completely right.
Can it be also related to access rights? The second user also tried to rename the file and he got the error related to access, I was the one person able to rename it.
Can I have your help? thank you a lot.
here is that part of code:
disp('Lettura Dati CSV')
[file,path]=uigetfile('*.csv','Select csv file to use');
filename=[path file];
Data = fileread(filename);
Data = strrep(Data, ',', '.');
FID = fopen(filename, 'w');
fwrite(FID, Data, 'char');
fclose(FID);
2 comentarios
Mario Malic
el 1 de Mzo. de 2024
It's the permission/access right. You have to grant permission for file reading/writing for other users.
Respuestas (2)
Harsh Mahalwar
el 5 de Mzo. de 2024
Hi Chiara,
From what I can gather, you have deployed a standalone application which reads the data from a csv file and when you login and try running the same csv file you had used before from a different user, MATLAB throws “invalid file identifier" error.
“invalid file identifier” error may occur due to the following reasons:
- excel.exe (or any other spreadsheet related application) might be running in the background.
Applications like ms excel, etc interfere while running and may not let your MATLAB Application to read/write the csv file properly. You can use the following line of code along with your snippet of code to make sure that excel is not running in the background.
system('taskkill /F /IM EXCEL.EXE /T');
I was able to reproduce this error while running excel.exe along with the specified csv file in the background.
2. Your MATLAB application might not have permissions to read/write the file you’ve specified.
- Try to access a file from a location where either you or MATLAB Application possesses full permissions, depending on your operating system.
- Running your application as an administrator (in Windows) may also help in tackling this problem.
You might find the information you're looking for in this Stack Overflow discussion I came across. Here's the link for you to explore further:
I hope this helps, thanks!
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!