From: Khanh on
So I have some files that I want to read all with 'sprintf'. If those files are named test1.txt, test2.txt, test3.txt... then I have no problem using
for k=1:n
sprintf('c:/folder/test%d.txt',k)

But if my files are name like text_0001.txt, text_0002.txt, and so on, I have not figured out away to use sprintf function to read those files.
Any suggestions?
From: dpb on
Khanh wrote:
> So I have some files that I want to read all with 'sprintf'. If those
> files are named test1.txt, test2.txt, test3.txt... then I have no
> problem using for k=1:n
> sprintf('c:/folder/test%d.txt',k)
>
> But if my files are name like text_0001.txt, text_0002.txt, and so on, I
> have not figured out away to use sprintf function to read those files.
> Any suggestions?

doc dir

--
From: Walter Roberson on
dpb wrote:
> Khanh wrote:
>> So I have some files that I want to read all with 'sprintf'. If those
>> files are named test1.txt, test2.txt, test3.txt... then I have no
>> problem using for k=1:n
>> sprintf('c:/folder/test%d.txt',k)
>>
>> But if my files are name like text_0001.txt, text_0002.txt, and so on,
>> I have not figured out away to use sprintf function to read those files.
>> Any suggestions?
>
> doc dir

sprintf('C:/folder/test%04d.txt',k)
From: Khanh on
Walter Roberson <roberson(a)hushmail.com> wrote in message <i3skm9$c6q$4(a)canopus.cc.umanitoba.ca>...
> dpb wrote:
> > Khanh wrote:
> >> So I have some files that I want to read all with 'sprintf'. If those
> >> files are named test1.txt, test2.txt, test3.txt... then I have no
> >> problem using for k=1:n
> >> sprintf('c:/folder/test%d.txt',k)
> >>
> >> But if my files are name like text_0001.txt, text_0002.txt, and so on,
> >> I have not figured out away to use sprintf function to read those files.
> >> Any suggestions?
> >
> > doc dir
>
> sprintf('C:/folder/test%04d.txt',k)

this does not solve the problem. How can you make it skip the "_" and all the zeroes.
If the text file goes up to like text_0012.txt, ...text_0112.txt,...
From: Walter Roberson on
Khanh wrote:
> Walter Roberson <roberson(a)hushmail.com> wrote in message
> <i3skm9$c6q$4(a)canopus.cc.umanitoba.ca>...
>> dpb wrote:
>> > Khanh wrote:
>> >> So I have some files that I want to read all with 'sprintf'. If
>> those >> files are named test1.txt, test2.txt, test3.txt... then I
>> have no >> problem using for k=1:n
>> >> sprintf('c:/folder/test%d.txt',k)
>> >>
>> >> But if my files are name like text_0001.txt, text_0002.txt, and so
>> on, >> I have not figured out away to use sprintf function to read
>> those files.
>> >> Any suggestions?
>> > > doc dir
>>
>> sprintf('C:/folder/test%04d.txt',k)
>
> this does not solve the problem. How can you make it skip the "_" and
> all the zeroes.
> If the text file goes up to like text_0012.txt, ...text_0112.txt,...

Sorry, make that
sprintf('C:/folder/test_%04d.txt',k)

And if that isn't a sufficient answer to your question, then I would
question how it is that you expect a function that formats strings for
output to be able to *read* files.

Have you considered dir('C:/folder/test_*.txt') ?