PDA

View Full Version : Renaming the files in all the folders



ygsunilkumar
07-11-2012, 01:37 AM
Hi,

I have folders located in c:\temp\ as shown below

a
b
c

In each folder, two files will be present that is .html and .gif file and named as

a.html and sgplot.gif
b.html and sgplot.gif
c.html and sgplot.gif

Now my requirement is to rename the sgplot.gif file to a.gif, b.gif and c.gif. Basically it has to rename as .html file name to .gif for all the folders located in c:\temp\
a
b
c

Please help me in achieving through excel macro.

Thanks in Advance

Trebor76
07-15-2012, 06:07 PM
Hi there,

Largely untested, but try this:


Option Explicit
Sub Macro1()

'http://www.vbaexpress.com/forum/showthread.php?t=42898

Dim strMyPath As String
Dim varArrayItem As Variant

strMyPath = "c:\temp\" 'Start directory. Make sure there's a trailing backslash.

For Each varArrayItem In Split("a,b,c", ",")
Name strMyPath & varArrayItem & "\sgplot.gif" As strMyPath & varArrayItem & "\" & varArrayItem & ".gif"
Next varArrayItem

End Sub

Regards,

Robert