We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

image help needed

coolguy2009
coolguy2009 asked
on
Medium Priority
259 Views
Last Modified: 2012-05-06
Hi,

I have a image files in directory"c:/images"

The file names are 1.jpg,2.jpg,atc.jpg etc...

I need a way to rename all the files inside the folder to thumb_1.jpg,thumb_2.jpg,thumb_atc.jpg etc...

Any help...
Comment
Watch Question

There was another question here on EE that was answering this exact same problem.  Check it out here:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_24142878.html

Author

Commented:
Hi,

That is the one he want to remove the words...But i need to append a word thumb_

That is not a solution i am expected..

Author

Commented:
Can anyone help me on this?

Try this

Ritesh
Sub renall()
Dim sPath, sFile, mFile, oFile As String
sPath = "D:\desktop\ee\"
sFile = Dir(sPath & "*.jpg")
 
Do While sFile <> ""
    oFile = sPath & sFile
    nfile = sPath & "thumb_" & sFile
    Name oFile As nfile
    sFile = Dir
Loop
End Sub

Open in new window

Please change sPath, Serach Path to your directory

Ritesh

Author

Commented:
I tried this nothing happens...

I saved this code in excel by alt f11 amd then i run alt f8...

Where i went wrong?What i did is correct?

Please advice...
Sub renall()
Dim sPath, sFile, mFile, oFile As String
sPath = "G:\thumb_images"
sFile = Dir(sPath & "*.jpg")
 
Do While sFile <> ""
    oFile = sPath & sFile
    nfile = sPath & "thumb_" & sFile
    Name oFile As nfile
    sFile = Dir
Loop
End Sub

Open in new window

Author

Commented:
Hi,

Here is my files and folder info...
ee-rename.JPG

Author

Commented:
I also change ur code?This also not renamed my files...
Sub renall()
Dim sPath, sFile, mFile, oFile As String
sPath = "G:\thumb_images"
sFile = Dir(sPath & "*.jpg")
 
Do While sFile <> ""
    oFile = sPath & sFile
    mFile = sPath & "thumb_" & sFile
    Name oFile As mFile
    sFile = Dir
Loop
End Sub

Open in new window

G:\thumb_images
Just put a back slash at hte end of it
G:\thumb_images\
and retry

Ritesh

Author

Commented:
I tried this..

File not found...
Sub renall()
Dim sPath, sFile, mFile, oFile As String
sPath = "G:\thumb_images\"
sFile = Dir(sPath & "*.jpg")
 
Do While sFile <> ""
    oFile = sPath & sFile
    mFile = sPath & "thumb_" & sFile
    Name oFile As mFile
    sFile = Dir
Loop
End Sub

Open in new window

Run this and post the result you get in debug window
Also make sure that g:\thumb_images exists

Ritesh
Sub renall()
Dim sPath, sFile, mFile, oFile As String
sPath = "G:\thumb_images\"
sFile = Dir(sPath & "*.jpg")
 
Do While sFile <> ""
    oFile = sPath & sFile
    mFile = sPath & "thumb_" & sFile
    Debug.Print sFile, oFile, mFile
    Name oFile As mFile
    sFile = Dir
Loop
End Sub

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Are you actually looking for a PHP script to rename the files (since you've posted your question in the PHP zone)?

the above VBA code SHOULD work, but after correctly renaming each file, it would rename thumb_1.jpg to thumb_thumb_1.jpg.  To prevent this (yet) unexplainable behaviour, the code should be changed as below:
Sub renall()
    Dim iCount, iLoop As Integer
    Dim sPath, mFile, oFile As String
    Dim sFile() As String
    ReDim sFile(1) As String
    sPath = "G:\thumb_images\"
    iCount = 1
    sFile(1) = Dir(sPath & "*.jpg")
    Do While sFile(iCount) <> ""
        iCount = iCount + 1
        ReDim Preserve sFile(iCount)
        sFile(iCount) = Dir
    Loop
    iCount = iCount - 1
    For iLoop = 1 To iCount
        oFile = sPath & sFile(iLoop)
        mFile = sPath & "thumb_" & sFile(iLoop)
        Name oFile As mFile
    Next
End Sub

Open in new window

It's always useful to place Option Explicit at the top of one's code so that errors are trapped. To make your macro function you need to change mFile to nFile

Sub renall()
Dim sPath, sFile, mFile, oFile As String
sPath = "G:\thumb_images\"
sFile = Dir(sPath & "*.jpg")
 
Do While sFile <> ""
    oFile = sPath & sFile
    mFile = sPath & "thumb_" & sFile
    Debug.Print sFile, oFile, mFile
    Name oFile As mFile
    sFile = Dir
Loop
End Sub
Oops - please ignore my last comment - someone has already trapped that error.

Patrick
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.