Re: directory sort
- From: "Markus" <no@xxxxxxxxx>
- Date: Tue, 4 Oct 2005 07:59:17 +0300
"James Griffin" <epxjmg@xxxxxxxxxxxxxxxx> wrote in message
news:ef16e72.-1@xxxxxxxxxxxxxxxxxxx
> To whom it may concern:
>
> I am getting a problem that doesn't want to go away. Firstly the
> files I have in directory ('C:\Results\asciioutput\t55\') a single
> column of numerical data with many files. The problem I am getting is
> sorting the files into order - both windows and Matlab only views the
> files in order but does not operate on the files in order (the files
> are in the form 1.txt, 2.txt... 10.txt, up to say 345.txt and the
> order will go 90 ....99.txt and then 9_.txt. The code below and
> windows 'view' 'details' sort name order all orcer the files
> correctly however when Matlab executes the program or one looks from
> MSDOS the files are not in sorted order
>
> currdir='C:\Results\asciioutput\t55\';
> d=dir(currdir);
> dd=sort({d.name});
>
> for i=1:length(dd)
> disp( dd{i} );
> end
>
> The above code is used to sort the current directory files however
> the sort is incorrect each time. Can anyone think of another command
> that sorts the directory into name or numerical order but at the
> MSDOS level and windows level.
>
> The rest of the code for the functionality of the program is as
> follows:
>
> %opdir='C:\testcases\OutputFiles\opfd1-14NoBurn1a.txt';
>
> %opdira='C:\testcases\OutputFiles\opfd1-14NoBurn1aFiles.txt'
>
> d=dir(currdir);
> catString = opdir;
> catString1 = opdira;
>
> % read in all files and directories within a directory
> for k=1:length(d)
>
> % get name and file/directory property of entities within a directory
>
> fname=d(k).name;
> dirif=d(k).isdir;
> datastore = 0;
>
> % check for file
> if dirif == 0
> %msgbox('not directory');
> pathread = strcat(currdir, fname)
> data=load(pathread);
> fid=fopen(catString, 'a');
>
> %appending 1024 * 1 double arrays (n files) data and output
> to file
>
>
> fprintf(fid, '%12.8f\n', data);
> st = fclose(fid)
>
> %append files names together and output to file
> fid=fopen(catString1, 'a');
> fprintf(fid, '%s\n', fname);
> st1 = fclose(fid)
>
> % count number of files
> h = h + 1;
>
> % check for directory
> elseif dirif == 1
> %msgbox('directory');
> % count number of directories
> g = g + 1;
> else
> msgbox('no directory or file');
> end
>
> end
>
> I would be grateful if anyone could throw some more light on this
> problem as I would like to move onto more interesting parts of the
> analysis but can not until I have sorted this very odd problem out.
>
> Kind Regards
>
> James
Quickly looking at your code makes me think that 'd' is not
sorted in your second for loop.
You should know that sorting files in MSDOS or Windows just affects the
order they are listed
for you to see. It has no affect on how they are processed internaly, so
to speak.
.
- References:
- directory sort
- From: James Griffin
- directory sort
- Prev by Date: Re: Out of memory when using princomp
- Next by Date: Re: Error converting Guide to executable
- Previous by thread: directory sort
- Next by thread: library model contains dynamic number of inputs
- Index(es):
Relevant Pages
|