Using dir to extract the names of plexon files for upload

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Caitli Newman
Caitli Newman il 9 Dic 2019
I believe .plx is the extension but if I try and do something like dir .plx it returns no files. I haven't worked with plexon files before so it has been a bit of a learning curve.
Stephen23
Stephen23 il 9 Dic 2019
Modificato: Stephen23 il 9 Dic 2019
Using cd like that is unlikely to work correctly.
Use absolute/relative filepaths instead, generating them using fullfile.
Is 'day1' supposed to be the name of a subfolder or a file?
Where do you specify the file extensions that you want to match?

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 9 Dic 2019
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});

dpb
dpb il 9 Dic 2019
Modificato: dpb il 9 Dic 2019
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... :)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by