Using dir to extract the names of plexon files for upload
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey I am trying to write a script that will scroll through all my folders and save the names of the plexon files I want. However matlab doesn't recognize the plexon file and thus keeps saving as an empty structure array and I don't know how to fix it.
D = dir;
D = D(~ismember({D.name}, {'.', '..'}));
for k = 1:numel(D)
currD=D(k).name
cd(currD)
dinfo=dir('day1')
end
dinfo =
0×1 empty struct array with fields:
name
folder
date
bytes
isdir
datenum
댓글 수: 3
답변 (2개)
Walter Roberson
2019년 12월 9일
cd(currD)
dinfo=dir('day1')
Don't do that. Instead
dinfo = dir(fullfile, currD, 'day1');
dinfo(ismember({dinfo.name}, {'.', '..'})) = [];
filenames = fullfile({dinfo.folder}, {dinfo.name});
댓글 수: 0
dpb
2019년 12월 9일
편집: dpb
2019년 12월 9일
targetDir='WhteverisDirNeeded';
d=dir(fullfile(targetDir, '*.plx')); % return all files of desired extension
for i=1:numel(d)
fname=fullfile(d(i).folder},d(i).name); % build qualified filename
...
Using the specific file extension will return only those files wanted. As others say, use a path to the desired directory instead of trying to cd all over the place. You don't provide enough info to know whether your location is relative to working directory or not so the minimum you can get away with isn't possible to say for the search directory. dir() returns a fully-qualified directory regardless of whether the search is absolute or relative.
You don't have to worry about the . or .. entries with this way with the one caveat you've not named a directory with a .plx extension. If you have, you deserve the grief... :)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!