Solved

rename in batch ,many photos in a dir , from a xls list column data ?

Posted on 2013-01-14
3
271 Views
Last Modified: 2013-01-14
i have a dir   "Photos_ID1"  in desktop , with photos named  all ready from a list of column ''B''  in sheet  "Prod_Photos" also there is a photo called "No_photo_yet.jpg"


   " A "                                         " B "          Dir  "Photos_ID1"      final result on dir
Su10000-M95-C413               156-0099          156-0099.jpg          Su10000-M95-C413.jpg
Su10001-M520-C41           140-1829          140-1829.jpg         Su10001-M520-C41.jpg                
Su10002-M95-C413               156-0145           156-0145.jpg       Su10002-M95-C413.jpg

1.         i want to compare the "B"  list with dir /photos and if i dont have photo with the selected value ,  i want  in  "B" column  to replace the cell  with value "No_photo_yet"

2nd ....i want to rename  the photos in dir ,with the "A" column

Do this for 6000 values in "B" or "A"
   

many thanks , to everyone that helps.
0
Comment
Question by:tonyantony
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 250 total points
ID: 38774116
with values listed in A & B (nothing in Columns C and D)...

Save the attached file in the "Photos_ID1" folder and run the following macro...

Sub Change_JPEG()

strPath = ThisWorkbook.Path
Dim xx As String
Dim arr

LastDataRow = Cells(Rows.Count, 1).End(xlUp).Row

arr = Range("A1:D" & LastDataRow).Value

For x = 1 To UBound(arr)
If Len(Dir(strPath & "\" & arr(x, 2) & ".jpg")) <> 0 Then
    Name strPath & "\" & arr(x, 2) & ".jpg" As strPath & "\" & arr(x, 1) & ".jpg"
    arr(x, 3) = strPath & "\" & arr(x, 2) & ".jpg"
    arr(x, 4) = strPath & "\" & arr(x, 1) & ".jpg"
Else
    arr(x, 3) = "No_photo_yet"
    arr(x, 4) = ""
End If
Next x
Range("A1:D" & LastDataRow).Value = arr

End Sub

Open in new window


Option 2 columns:
Sub Change_JPEG()

strPath = ThisWorkbook.Path
Dim xx As String
Dim arr

LastDataRow = Cells(Rows.Count, 1).End(xlUp).Row

arr = Range("A1:B" & LastDataRow).Value

For x = 1 To UBound(arr)
If Len(Dir(strPath & "\" & arr(x, 2) & ".jpg")) <> 0 Then
    Name strPath & "\" & arr(x, 2) & ".jpg" As strPath & "\" & arr(x, 1) & ".jpg"
Else
    arr(x, 2) = "No_photo_yet"
End If
Next x
Range("A1:B" & LastDataRow).Value = arr
End Sub

Open in new window

Dir-change.xlsm
Dir-change.xlsm
0
 

Author Closing Comment

by:tonyantony
ID: 38775738
i tested 1st macro ,  no need for the other, works fine many thanks , good job
0
 
LVL 24

Expert Comment

by:Steve
ID: 38775758
Glad to help, I just did the second as it was what you asked for, but I thought leaving the original data alone was a cleaner result.

ATB
Steve.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel If Statement 3 25
Macro that Locks & Unlocks Worksheet 4 28
Modify Array formula - Reduce Calculation Time 4 30
Hash on Excel 13 40
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

756 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