User input file directory
Show older comments
I am writing a script that reads all of the files of a certain type in a given directory, and I'm wondering if there is a way to allow the directory location to be a user input.
Currently the code looks like:
directory_in = dir('C:\Folder\Bob\*.dat');
I would like to change it to something more like:
input_in = input('Enter the directory name: ');
directory_in = dir(input_in, '*.dat');
I know this code won't work as written for multiple reasons, but I'm wondering if there is some way I could combine the user input with the file type suffix in order to minimize the amount of editing a future user would need to perform on the script.
Accepted Answer
More Answers (2)
Azzi Abdelmalek
on 26 Jul 2016
0 votes
Use uigetdir
Bob Thompson
on 27 Jul 2016
0 votes
4 Comments
Star Strider
on 27 Jul 2016
That function seems to be a File Exchange contribution, since I can’t find it in the documentation.
The uigetfile is the only built-in function that seems to be close to it.
Bob Thompson
on 27 Jul 2016
Edited: Bob Thompson
on 27 Jul 2016
Image Analyst
on 27 Jul 2016
I don't understand. Do you not trust the users to pick the proper files? If not, then you can use dir() to specify the proper file pattern once they've chosen the folder via any of the other functions (uigetdir, uigetfile, or uipickfiles).
Bob Thompson
on 28 Jul 2016
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!