Effacer les filtres
Effacer les filtres

Standalone Application - fwrite invalid file identifier if launched by another user

1 vue (au cours des 30 derniers jours)
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');
  2 commentaires
Mario Malic
Mario Malic le 1 Mar 2024
It's the permission/access right. You have to grant permission for file reading/writing for other users.
Chiara le 1 Mar 2024
I supposed so. In the mean time I fixed by using copyfile , so that the application always works on a copy of the original file and it always has the rights.

Connectez-vous pour commenter.

Réponses (2)

Harsh Mahalwar
Harsh Mahalwar le 5 Mar 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:
  1. 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!
  1 commentaire
Chiara le 5 Mar 2024
Hi Harsh,
yes, the error is the same you can also get when trying to read a file if still open on excel, but your view maybe misses some details. I add some points:
when I log in, after I launch the application, it asks for a csv. If I select one of the files I have uploaded to that folder, it's ok and it's still ok even when I close the application and re launch it and select the same file to read. It means that the application code correctly closes the file and excel close aswell, otherwise I would receive that error even in this case.
If instead, in the second try, I select another csv, loaded by another user, I get that error.
I think it's more related to some particular restrictions applied by my company in terms of write-rights and it's confirmed by the comment I posted after the previous answer where I describe how i fixed.
For sure your hint can make the execution even more reliable.
Thanks a lot.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 6 Mar 2024
Maybe try
in the code where your app shuts down.




Community Treasure Hunt

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

Start Hunting!

Translated by