shorten files based on content in a range

thinksuccess

New Member
Joined
Jan 29, 2003
Messages
16
Hi,

I have a list of image files that were auto generated and thus contain letters and or numbers that should not be there.

Here is an example of what I want to be able to do.

Rename: AT4040_t_16140.jpg

To: AT4040.jpg

Basically the "_t_and anything betweeen the .jpg is what I want to get rid of.


Thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
lets say the file name was in A1 then type this in B1

=LEFT(A1,FIND("_",A1,1)-1)&".jpg"

This should get you started.

-Jacob
 
Upvote 0
The other part you might need is the Name Statement from VBA. From VB Help:
Name Statement Example
This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. On the Macintosh, “HD:” is the default drive name and portions of the pathname are separated by colons instead of backslashes.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.
 
Upvote 0
(y)
Thanks DRJ! That worked perfect!

Now if I could just figure out how to actually rename the images on the server :)
 
Upvote 0
See if Greg Truby's solution helps you. If not we can come up with something else.
 
Upvote 0
The problem is all my images are auto generated on a unix server so I would need some type of rename script. Actually the rename script I use now just for lowercase of the extensions is:

#!/usr/bin/perl -w
#
#

chomp($L = `ls -1 *.jpg *.JPG`);

@fls = split(/\n/, $L);

foreach $i (@fls) {
($name, $ext) = split(/\./, $i);
rename($i, uc($name).".".lc($ext));
}

If this could be modifed to do what I need that would be great!

I know this is an excel board but you guys are so smart I'm confident someone can come up with something.

Thanks Again!
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,746
Members
449,050
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top