Re: reading file list, writing to text file
- From: sillystring.theory@xxxxxxxxx
- Date: 27 Aug 2006 11:30:13 -0700
d=dir('*.jpg');
for k=1:length(d)
fname=d(k).name;
fname %check it is reading all files
fid=fopen('list.txt', 'w');
count = fprintf(fid, fname);
fclose(fid)
end
The problem I have is that even though the program correctly reads
through all the files, only the last read file is stored in the text
file....I presume the text file is just constantly being overwritten.
Hello Monkey,
The reason your loop is overwriting the previous text file is that you
are opening the text file not in append mode.
Also, you should not open the file for reading multiple times - that is
the slowest part of this loop by far. You ought to store all the file
names in an array and at the end of the loop, write the entire array to
file, just once.
d=dir('*.jpg');
myfname = [];
for k=1:length(d)
myfname = [myfname d(k).name ' ' ];
end
fid = fopen('list.txt', 'w');
count = fprintf( fid, myfname );
Does this help, I hope?
~Helen Lurie
.
- References:
- reading file list, writing to text file
- From: monkey boy
- reading file list, writing to text file
- Prev by Date: Generalized Method of Moments
- Next by Date: Re: reading file list, writing to text file
- Previous by thread: reading file list, writing to text file
- Next by thread: Re: reading file list, writing to text file
- Index(es):
Relevant Pages
|
Loading