Jerry
Jerry

Reputation: 107

Loading .dat files from sub folders

I have the following code; clear clc for n = 1:20 foldername = sprintf('G:\\Protable Hard Drive\\PHD Hard Drive\\Experimental Data\\Bulkrename Trial\\TSR7.85\\Center Left P%d\\0.66D', n) dir(foldername) datfiles = dir(fullfile('.', 'foldername', '*.dat')) end

From this I can access the subfolder 0.66D which is in a parent folder called Center Left P%d with %d ranging from 1 to 20. With the dir command I can clearly see the files of each sub folder listed in the command window; `foldername =

G:\Protable Hard Drive\PHD Hard Drive\Experimental Data\Bulkrename Trial\TSR7.85\Center Left P1\0.66D

. 0_66D.R0027 0_66D.S0017 0_66D.T0007 0_66D.T0035 0_66D.V0025 POINT775.dat
.. 0_66D.R0028 0_66D.S0018 0_66D.T0008 0_66D.T0036 0_66D.V0026 POINT776.dat
0_66D.R0001 0_66D.R0029 0_66D.S0019 0_66D.T0009 0_66D.T0037 0_66D.V0027 POINT777.dat
0_66D.R0002 0_66D.R0030 0_66D.S0020 0_66D.T0010 0_66D.T0038 0_66D.V0028 POINT778.dat
0_66D.R0003 0_66D.R0031 0_66D.S0021 0_66D.T0011 0_66D.V0001 0_66D.V0029 POINT779.dat
0_66D.R0004 0_66D.R0032 0_66D.S0022 0_66D.T0012 0_66D.V0002 0_66D.V0030 POINT780.dat
0_66D.R0005 0_66D.R0033 0_66D.S0023 0_66D.T0013 0_66D.V0003 0_66D.V0031 POINT781.dat
0_66D.R0006 0_66D.R0034 0_66D.S0024 0_66D.T0014 0_66D.V0004 0_66D.V0032 POINT782.dat
0_66D.R0007 0_66D.R0035 0_66D.S0025 0_66D.T0015 0_66D.V0005 0_66D.V0033 POINT783.dat
0_66D.R0008 0_66D.R0036 0_66D.S0026 0_66D.T0016 0_66D.V0006 0_66D.V0034 POINT784.dat
0_66D.R0009 0_66D.R0037 0_66D.S0027 0_66D.T0017 0_66D.V0007 0_66D.V0035 POINT785.dat
0_66D.R0010 0_66D.R0038 0_66D.S0028 0_66D.T0018 0_66D.V0008 0_66D.V0036 POINT786.dat
0_66D.R0011 0_66D.S0001 0_66D.S0029 0_66D.T0019 0_66D.V0009 0_66D.V0037 POINT787.dat
0_66D.R0012 0_66D.S0002 0_66D.S0030 0_66D.T0020 0_66D.V0010 0_66D.V0038 POINT788.dat
0_66D.R0013 0_66D.S0003 0_66D.S0031 0_66D.T0021 0_66D.V0011 POINT761.dat POINT789.dat
0_66D.R0014 0_66D.S0004 0_66D.S0032 0_66D.T0022 0_66D.V0012 POINT762.dat POINT790.dat
0_66D.R0015 0_66D.S0005 0_66D.S0033 0_66D.T0023 0_66D.V0013 POINT763.dat POINT791.dat
0_66D.R0016 0_66D.S0006 0_66D.S0034 0_66D.T0024 0_66D.V0014 POINT764.dat POINT792.dat
0_66D.R0017 0_66D.S0007 0_66D.S0035 0_66D.T0025 0_66D.V0015 POINT765.dat POINT793.dat
0_66D.R0018 0_66D.S0008 0_66D.S0036 0_66D.T0026 0_66D.V0016 POINT766.dat POINT794.dat
0_66D.R0019 0_66D.S0009 0_66D.S0037 0_66D.T0027 0_66D.V0017 POINT767.dat POINT795.dat
0_66D.R0020 0_66D.S0010 0_66D.S0038 0_66D.T0028 0_66D.V0018 POINT768.dat POINT796.dat
0_66D.R0021 0_66D.S0011 0_66D.T0001 0_66D.T0029 0_66D.V0019 POINT769.dat POINT797.dat
0_66D.R0022 0_66D.S0012 0_66D.T0002 0_66D.T0030 0_66D.V0020 POINT770.dat POINT798.dat
0_66D.R0023 0_66D.S0013 0_66D.T0003 0_66D.T0031 0_66D.V0021 POINT771.dat master.bak
0_66D.R0024 0_66D.S0014 0_66D.T0004 0_66D.T0032 0_66D.V0022 POINT772.dat vtmp.000
0_66D.R0025 0_66D.S0015 0_66D.T0005 0_66D.T0033 0_66D.V0023 POINT773.dat vtmp.001
0_66D.R0026 0_66D.S0016 0_66D.T0006 0_66D.T0034 0_66D.V0024 POINT774.dat `

However when I try to load all the .dat files within each subfolder into my workspace, I get the following error; `datfiles =

0x1 struct array with fields:

name
date
bytes
isdir
datenum`

Can anyone explain to me why this is happening? Regards, Jerry

Upvotes: 0

Views: 141

Answers (1)

Daniel
Daniel

Reputation: 36710

Please check the output of fullfile('.', 'foldername', '*.dat'), there are no files in .\foldername\*.dat. foldername is a variable, don't use quotation marks, and the leading . does not make sense when combined with an absolute path.

Upvotes: 1

Related Questions