Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to change filenames quickly?

Subject: How to change filenames quickly?

From: Diego Zegarra

Date: 5 Feb, 2009 16:44:02

Message: 1 of 7

I have a bunch of files having the following pattern,

20on2Rp50Rs50_1.dat
20on2Rp50Rs50_2.dat
20on2Rp50Rs50_3.dat
40on2Rp50Rs50_1.dat
40on2Rp50Rs50_2.dat
40on2Rp50Rs50_3.dat
60on2Rp50Rs50_1.dat
60on2Rp50Rs50_2.dat
60on2Rp50Rs50_3.dat
20on4Rp50Rs50_1.dat
20on4Rp50Rs50_2.dat
20on4Rp50Rs50_3.dat
40on4Rp50Rs50_1.dat
40on4Rp50Rs50_2.dat
40on4Rp50Rs50_3.dat
60on4Rp50Rs50_1.dat
60on4Rp50Rs50_2.dat
60on4Rp50Rs50_3.dat

And so on, I want them to change the part 50Rs50 to 70Rs30 but I have around 1000 files and dont want to do it one by one.

Any one knows how I can do this? Any help is greatly appreciated!

Subject: How to change filenames quickly?

From: Rune Allnor

Date: 5 Feb, 2009 16:50:28

Message: 2 of 7

On 5 Feb, 17:44, "Diego Zegarra" <diego...@gmail.com> wrote:
> I have a bunch of files having the following pattern,
>
> 20on2Rp50Rs50_1.dat
> 20on2Rp50Rs50_2.dat
> 20on2Rp50Rs50_3.dat
> 40on2Rp50Rs50_1.dat
> 40on2Rp50Rs50_2.dat
> 40on2Rp50Rs50_3.dat
> 60on2Rp50Rs50_1.dat
> 60on2Rp50Rs50_2.dat
> 60on2Rp50Rs50_3.dat
> 20on4Rp50Rs50_1.dat
> 20on4Rp50Rs50_2.dat
> 20on4Rp50Rs50_3.dat
> 40on4Rp50Rs50_1.dat
> 40on4Rp50Rs50_2.dat
> 40on4Rp50Rs50_3.dat
> 60on4Rp50Rs50_1.dat
> 60on4Rp50Rs50_2.dat
> 60on4Rp50Rs50_3.dat
>
> And so on, I want them to change the part 50Rs50 to 70Rs30 but I have around 1000 files and dont want to do it one by one.
>
> Any one knows how I can do this? Any help is greatly appreciated!

In R2006a you can use COPYFILE to copy the file
to a new place, and then use DELETE to remove the old.

There might be a RENAME function in later editions
of matlab, check out the docs for COPYFILE and see.

Rune

Subject: How to change filenames quickly?

From: Adam

Date: 5 Feb, 2009 17:09:02

Message: 3 of 7

"Diego Zegarra" <diegozbb@gmail.com> wrote in message
> 60on4Rp50Rs50_3.dat
>
> And so on, I want them to change the part 50Rs50 to 70Rs30 but I have around 1000 files and dont want to do it one by one.
>
> Any one knows how I can do this? Any help is greatly appreciated!

Open the dos prompt. Navigate to your directory

rename ???????50Rs50*.dat ???????70Rs30*.dat

Might want to make a backup copy of your directory first in case you run into issues.

Hmmm, actually you might want to do
mkdir newfiles
copy ???????50Rs50*.dat newfiles\???????70Rs30*.dat

Then you can delete the originals if you're happy with the results.

~Adam

Subject: How to change filenames quickly?

From: ImageAnalyst

Date: 5 Feb, 2009 17:11:14

Message: 4 of 7

Check out these functions that could help
dir Gets existing filenames
fileparts Gets path, basefilename, extension
sprintf Lets you build up the new basefilename
fullfile Makes a complete filename from path, basefilename, and
extension
rename Gives the existing file a new name. Does not create a new,
additional file.
copyfile Creates a new file with a new name from the old file/old
name.

You'll probably use them in roughly that order

Subject: How to change filenames quickly?

From: ImageAnalyst

Date: 5 Feb, 2009 17:12:44

Message: 5 of 7

On Feb 5, 12:11=A0pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> Check out these functions that could help
> dir =A0 =A0Gets existing filenames
> fileparts =A0 Gets path, basefilename, extension
> sprintf =A0 =A0Lets you build up the new basefilename
> fullfile =A0 Makes a complete filename from path, basefilename, and
> extension
> rename =A0Gives the existing file a new name. =A0Does not create a new,
> additional file.
> copyfile =A0Creates a new file with a new name from the old file/old
> name.
>
> You'll probably use them in roughly that order

You may also make use of the strrep() function in making up your new
filenames. It replaces substrings with new ones.

Subject: How to change filenames quickly?

From: Diego Zegarra

Date: 5 Feb, 2009 19:31:02

Message: 6 of 7

Thanks a lot Adam, worked perfect on the command prompt!

Subject: How to change filenames quickly?

From: Naresh Pai

Date: 14 Jun, 2009 02:53:01

Message: 7 of 7

"Adam" <not.real@email.com> wrote in message <gmf6fe$b0i$1@fred.mathworks.com>...
> "Diego Zegarra" <diegozbb@gmail.com> wrote in message
> > 60on4Rp50Rs50_3.dat
> >
> > And so on, I want them to change the part 50Rs50 to 70Rs30 but I have around 1000 files and dont want to do it one by one.
> >
> > Any one knows how I can do this? Any help is greatly appreciated!
>
> Open the dos prompt. Navigate to your directory
>
> rename ???????50Rs50*.dat ???????70Rs30*.dat
>
> Might want to make a backup copy of your directory first in case you run into issues.
>
> Hmmm, actually you might want to do
> mkdir newfiles
> copy ???????50Rs50*.dat newfiles\???????70Rs30*.dat
>
> Then you can delete the originals if you're happy with the results.
>
> ~Adam

I have a similar question as above but instead of changing from 50 to 70, I need to insert to digits before 50. For example I need to change 60on4Rp50Rs50_3.dat to 60on4Rp1950Rs50_3.dat

Tags for this Thread

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.

Contact us