?
Solved

image help needed

Posted on 2009-02-14
14
Medium Priority
?
233 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...
0
Comment
Question by:coolguy2009
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 5

Expert Comment

by:FirstDownMage
ID: 23643917
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
0
 

Author Comment

by:coolguy2009
ID: 23643940
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..
0
 

Author Comment

by:coolguy2009
ID: 23644001
Can anyone help me on this?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:riteshparakh
ID: 23644003
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

0
 
LVL 10

Expert Comment

by:riteshparakh
ID: 23644006
Please change sPath, Serach Path to your directory

Ritesh
0
 

Author Comment

by:coolguy2009
ID: 23644147
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

0
 

Author Comment

by:coolguy2009
ID: 23644171
Hi,

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

Author Comment

by:coolguy2009
ID: 23644176
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

0
 
LVL 10

Expert Comment

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

Ritesh
0
 

Author Comment

by:coolguy2009
ID: 23645641
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

0
 
LVL 10

Accepted Solution

by:
riteshparakh earned 800 total points
ID: 23645703
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

0
 
LVL 4

Assisted Solution

by:Ledigimate
Ledigimate earned 800 total points
ID: 23648424
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

0
 
LVL 45

Assisted Solution

by:patrickab
patrickab earned 400 total points
ID: 23648792
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
0
 
LVL 45

Expert Comment

by:patrickab
ID: 23648800
Oops - please ignore my last comment - someone has already trapped that error.

Patrick
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question