Thread Subject:
rename 1000 files

Subject: rename 1000 files

From: Jose

Date: 4 Sep, 2010 10:21:07

Message: 1 of 6

Hello to everyone, I've got 1000 files spt in adirectory called c:\matlabfiles\spt\ and I want to save it in files with the same name but with a new extention sp.

Look at the code.

How can I do that in an efficient and fast way, because hand by hand is going to be a nightmare!!!

Thanks in advance.

time=50; % seconds
fs=25000; % sample rate: points/sec
npoints=time*fs;
ns=20;

TT=readspt('13lola00-6-1.spt');
TT=TT/8; % conversion to bytes = fs/(fs*8)
fh=fopen ('13lola00-60.sp','r');
fseek(fh,TT(1)*2,0) % The number 2 is related by 'short'----> 1 point = 2bytes.
data=fread(fh,[1,2*npoints],'short')';
fclose (fh);

Subject: rename 1000 files

From: Miroslav Balda

Date: 4 Sep, 2010 10:39:35

Message: 2 of 6

"Jose " <jose.l.vega@gmail.com> wrote in message <i5t6ij$8iq$1@fred.mathworks.com>...
> Hello to everyone, I've got 1000 files spt in adirectory called c:\matlabfiles\spt\ and I want to save it in files with the same name but with a new extention sp.
>
> Look at the code.
>
> How can I do that in an efficient and fast way, because hand by hand is going to be a nightmare!!!
>
> Thanks in advance.
>
> time=50; % seconds
> fs=25000; % sample rate: points/sec
> npoints=time*fs;
> ns=20;
>
> TT=readspt('13lola00-6-1.spt');
> TT=TT/8; % conversion to bytes = fs/(fs*8)
> fh=fopen ('13lola00-60.sp','r');
> fseek(fh,TT(1)*2,0) % The number 2 is related by 'short'----> 1 point = 2bytes.
> data=fread(fh,[1,2*npoints],'short')';
> fclose (fh);

Hi Jose,

Maybe the fdunction freename from FEX could help you.
        www.mathworks.com/matlabcentral/fileexchange/9036

Mira

Subject: rename 1000 files

From: Jose

Date: 4 Sep, 2010 12:30:10

Message: 3 of 6

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i5t7l7$gd1$1@fred.mathworks.com>...
> "Jose " <jose.l.vega@gmail.com> wrote in message <i5t6ij$8iq$1@fred.mathworks.com>...
> > Hello to everyone, I've got 1000 files spt in adirectory called c:\matlabfiles\spt\ and I want to save it in files with the same name but with a new extention sp.
> >
> > Look at the code.
> >
> > How can I do that in an efficient and fast way, because hand by hand is going to be a nightmare!!!
> >
> > Thanks in advance.
> >
> > time=50; % seconds
> > fs=25000; % sample rate: points/sec
> > npoints=time*fs;
> > ns=20;
> >
> > TT=readspt('13lola00-6-1.spt');
> > TT=TT/8; % conversion to bytes = fs/(fs*8)
> > fh=fopen ('13lola00-60.sp','r');
> > fseek(fh,TT(1)*2,0) % The number 2 is related by 'short'----> 1 point = 2bytes.
> > data=fread(fh,[1,2*npoints],'short')';
> > fclose (fh);
>
> Hi Jose,
>
> Maybe the fdunction freename from FEX could help you.
> www.mathworks.com/matlabcentral/fileexchange/9036
>
> Mira

Thnak you Mira,it looks I have to rename all my files .spt from the main directory with your function, I mean... transform my files name 13lola00--1.spt into data001.spt...and afterward to convert it to the new extention result001.sp.

My question is, I have to rename my files 13lola..., 13ico... hand by hand?, or you can get all of them from the directory ones...if it is hand by hand, agin is a nightmare.

Please, could you explain me if your function can collect all my 1000 spt files and convert to data001.spt.....data1000.spt?

Thanks,

Subject: rename 1000 files

From: per isakson

Date: 4 Sep, 2010 14:05:09

Message: 4 of 6

"Jose " <jose.l.vega@gmail.com> wrote in message <i5te4i$768$1@fred.mathworks.com>...
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i5t7l7$gd1$1@fred.mathworks.com>...
> > "Jose " <jose.l.vega@gmail.com> wrote in message <i5t6ij$8iq$1@fred.mathworks.com>...
> > > Hello to everyone, I've got 1000 files spt in adirectory called c:\matlabfiles\spt\ and I want to save it in files with the same name but with a new extention sp.
> > >
> > > Look at the code.
> > >
> > > How can I do that in an efficient and fast way, because hand by hand is going to be a nightmare!!!
> > >
> > > Thanks in advance.
> > >
> > > time=50; % seconds
> > > fs=25000; % sample rate: points/sec
> > > npoints=time*fs;
> > > ns=20;
> > >
> > > TT=readspt('13lola00-6-1.spt');
> > > TT=TT/8; % conversion to bytes = fs/(fs*8)
> > > fh=fopen ('13lola00-60.sp','r');
> > > fseek(fh,TT(1)*2,0) % The number 2 is related by 'short'----> 1 point = 2bytes.
> > > data=fread(fh,[1,2*npoints],'short')';
> > > fclose (fh);
> >
> > Hi Jose,
> >
> > Maybe the fdunction freename from FEX could help you.
> > www.mathworks.com/matlabcentral/fileexchange/9036
> >
> > Mira
>
> Thnak you Mira,it looks I have to rename all my files .spt from the main directory with your function, I mean... transform my files name 13lola00--1.spt into data001.spt...and afterward to convert it to the new extention result001.sp.
>
> My question is, I have to rename my files 13lola..., 13ico... hand by hand?, or you can get all of them from the directory ones...if it is hand by hand, agin is a nightmare.
>
> Please, could you explain me if your function can collect all my 1000 spt files and convert to data001.spt.....data1000.spt?
>
> Thanks,

I'm not sure I understand your question. Do you mean renaming 1000 files? If so and you are on Windows: see http://www.computerhope.com/renamehl.htm. I take for granted that UNIX/LINUX has something similar.

Rename all text files to files with .bak extension.
rename *.txt *.bak

/ per


 

Subject: rename 1000 files

From: Steven_Lord

Date: 5 Sep, 2010 03:28:43

Message: 5 of 6



"Jose " <jose.l.vega@gmail.com> wrote in message
news:i5t6ij$8iq$1@fred.mathworks.com...
> Hello to everyone, I've got 1000 files spt in adirectory called
> c:\matlabfiles\spt\ and I want to save it in files with the same name but
> with a new extention sp.
>
> Look at the code.
>
> How can I do that in an efficient and fast way, because hand by hand is
> going to be a nightmare!!!

Write a line of code that accepts a file name and renames that one file.

Then execute that line of code using the technique described in question
4.12 in the newsgroup FAQ.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: rename 1000 files

From: Miroslav Balda

Date: 5 Sep, 2010 21:34:04

Message: 6 of 6

"Jose " <jose.l.vega@gmail.com> wrote in message <i5te4i$768$1@fred.mathworks.com>...
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i5t7l7$gd1$1@fred.mathworks.com>...
> > "Jose " <jose.l.vega@gmail.com> wrote in message <i5t6ij$8iq$1@fred.mathworks.com>...
...
SNIP
...
> Please, could you explain me if your function can collect all my 1000 spt files and convert to data001.spt.....data1000.spt?

Hi Jose,

I have to apologize for my response, because it did not answer your question. The followingcode may help you to solve your task:

% Jose.m
D = dir('*.spt');
for k = 3:length(D)
    fnamein = D(k).name;
    [pth,name] = fileparts(fnamein);
    finp = fopen(fnamein,'rt');
% Read your file and modify it into array 'newdata'
% The following command is only for copying without modification
        newdata = fread(finp,'*char');
    fclose(finp);
    fnameout = [name '.sp'];
    fout = fopen(fnameout,'wt');
        fprintf(fout,'%s\n',newdata);
    fclose(fout);
end

You have to modify it in the place of comments for your purpose.
Hope it help.

Mira

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us