How to access files inside a package or a class folder?

4 views (last 30 days)
Hello,
I have the organized my classes in a package as follows: * ./+myPck/@myClassA/myClassA.m * ./+myPck/@myClassB/myClassB.m
In the methods of myClassB, I need to:
  • read file.txt, a file provided with the package and not meant to be changed
  • read and modify var.txt, a file provided as default by the package, but which can be modified by the methods of myClassB
  • the default var.txt should be kept unmodified for new instances of myClassB.
How can I do that properly? The end user should not see file.txt and var.txt in his current folder, it should be kept hidden from him.
Therefore, 2 questions:
  • Is it possible to have for instance a folder ./+myPck/src with all read only files that I need? How can I access them, given that ./+myPck is not my current folder, potentially also not a subfolder from the current folder.
  • How can I write new files that still stay hidden (that is, which are not in the current folder) from the end user? I could maybe write them inside the +myPck folder, but I don't know if it's a good practice to pollute the +myPck folder with generated file, especially in the case the package folder is transmitted to other user... A potential solution I've thought of: a +myPck/tmp folder where files are written in, which could be emptied when the object is deleted. However I think this solution is not very "best practice", and doesn't work when 2 instances of myClassB are created, but only 1 deleted: the files of the second one in the tmp folder are also deleted...
I couldn't find help about this problem in the doc. I would be very glad for any advice. Thank you.
Jo.
  1 Comment
John Breuer
John Breuer on 11 Feb 2022
Hi Jo,
did you find a solution to this problem? I am facing a similar case in which I want to contain source files directly within the classpath that the class is supposed to access when loading default properties, e.g., a text file, or an image, etc.
It would be great to get an answer about this.
John

Sign in to comment.

Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!