Read files from a different directory in standalone applications

Hello,
Please help me with the following:
I create a standalone executable with Application Compiler App (I am using R2017a).
Then I install the application in Program Files.
To run the Application (namely Model_A), I go to the Command Prompt and type:
application\Model_A
Model_A starts to run and read files from the directory that is installed in Program Files.
How can read files from another directory, for example, C:/users/user1/Desktop/Folder1?
should I use a command in command prompt that redirects Model_A from Program files to Folder 1?
Thank you.
Best,
Pavlos

 Accepted Answer

You need to modify your Model_A so that it asks the user to select a directory to read the files from. That way, you'll give the user the freedom to choose any folder he/she wants.
You could use uigetdir ,
folder_name = uigetdir
This command opens up a dialogbox to let the user browse through explorer to select a folder. You can write it in one of the scripts/function which reads the files from the folder, like
folderInfo = dir(folder_name);

4 Comments

This works perfect. The user defines the path after the command
application\Model_A
But I needed to set it in the same line with application/Model_A in cmd.
Maybe modify the code in something like this?
function Model_A()
path=....
You would only need to add the lines I gave you inside your function to get the path of your folder. After that you can read the files on that folder, which I assume you know how to do.
When you call your Model_A from the command line, during the execution, a dialogbox appears and asks the user to select a directory. This will then enable the latter part pf the program to read files. So on the command prompt, you will only have to call your executable.
Thanks for the help.
Really appreciate it.
This won't be working for a standalone app. It may work before you convert it into standalone app. For me, since I haven't got yet the solution, I copy the app into my project folder to operate it.

Sign in to comment.

More Answers (1)

You can set your directory to a file which contains both Program Files and Folder1.

5 Comments

Thank you for your response.
Can you please be more specific?
When the modelA starts to run, you also want to run the files from C:/users/user1/Desktop/Folder1. Then, all you have to do is to carry the Folder1 to the folder where the modelA files take place, so that they will be in the same directory. You can not set two directories at the same time.
Yes, thank you. This works.
But what I need is a command for cmd of windows to read files from a different folder.
For example, something like this:
application\Model_A "C:/users/user1/Desktop/Folder1"
When I give this command, I get the message:
MATLAB:scriptNotAFunction
application\Model_A "C:/users/user1/Desktop/Folder1"
When you do this, the spacing between modelA and "C... gives a command that application\Model_A is a function and the next statement will be its input. So it is invalid that you try to write like that. Use
cd
command for changing the directory. Let me know what happens.
I am writing this:
CD C:\users\user1\Program Files
in order to go the installation folder of Model_A.
Next, I give the following command:
application\Model_A cd C:/users/user1/Desktop/Folder1
and I get the same error.

Sign in to comment.

Categories

Products

Asked:

on 19 Oct 2017

Commented:

on 25 Feb 2023

Community Treasure Hunt

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

Start Hunting!