Avoid opening file multiple times using winopen

Hi, I am building a GUI in which for given inputs by the user several pdf files are opened. The same file can be opened multiple times for different inputs, yet I want each file to be opened only once. Is there any elegant way to do so without using counters?

3 comentarios

Adam Danz
Adam Danz el 31 de Dic. de 2020
Editada: Adam Danz el 31 de Dic. de 2020
> Is there any elegant way to do so
Not really, assuming your GUI isn't the cause of the problem.
Some operating systems and programs that open the file can be set to avoid opening duplicates but Matlab does not have any control of that that I know of. Furthremore, even if you use a counter or store a list of documents that were accessed, the matlab program wouldn't know if the user manually closed those files.
If your GUI is listing duplicate files to open within the same command, that could be easily fixed, of course (unique()). Example:
docs = {'myfile0.pdf', 'myfile1.pdf', 'myfile1.pdf', 'myfile2.pdf'};
% [^ duplicate]
for i = 1:numel(docs)
winopen(docs{i};)
end
Mario Malic
Mario Malic el 1 de En. de 2021
Editada: Mario Malic el 1 de En. de 2021
That'll be tricky to do, especially for the reason that Adam mentioned and how fileattrib works.
On Windows, using Adobe Reader, the program itself doesn't lock the PDF file, therefore you can't use fileattrib as an indication whether the file is opened or not.
If you take a look at this answer, you can probably create a process for each PDF file (which will open many instances of PDF reader), but you have an indication whether the process is opened or not, otherwise you can use actxserver if it's available for your application. With actxserver you can probably open your PDF files in tabs and it'll be much cleaner.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Preguntada:

el 31 de Dic. de 2020

Editada:

el 1 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by