How can I create a string with name of a searched file?

1 view (last 30 days)
Hi,
I have some files in a directory from which I have to search and get names of files containing string "bc". So, I have this code.
file_search_with_name = strcat('dir /B /S *bc*.txt');
[status, list] = system('dir /B /S *bc*.txt');
result = textscan(list,'%s','delimiter','\n' );
files = result{1};
In files I get strings which contain the filenames with entire path, like this.
files{1,1}
ans =
C:\Users\sj028179\Documents\Work\a\abcd.txt
How can I get rid of the directory path and just keep the filename in a string, like "abcd.txt"?
Thanks for the help.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 7 Aug 2015
f='your_folder'
d=dir(fullfile(f,'*bc*.txt'))
file={d.name}

More Answers (0)

Categories

Find more on File Operations 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!