PDA

View Full Version : Change file extensions



YasserKhalil
03-14-2017, 09:45 AM
Hello everyone
Is there a way to convert png files to jpg file in specific folder (the folder has sub folders with other files and pbg is there too)?
Thanks advanced for help

I have posted the same thread at this link
http://www.eileenslounge.com/viewtopic.php?f=30&t=26294&p=203938#p203938

mdmackillop
03-14-2017, 12:33 PM
Check out Irfanview. There is probably a command line conversion also which can be run through a Shell command.
https://www.bleepingcomputer.com/forums/t/50519/simple-batch-conversion-using-irfanview/

Command lines
http://www.robvanderwoude.com/files/iviewcli.txt

YasserKhalil
03-14-2017, 01:08 PM
Thanks a lot Mr. mdmackillop (http://www.vbaexpress.com/forum/member.php?87-mdmackillop) for these links. I had a look but I am lost in fact and couldn't get start point

mdmackillop
03-14-2017, 01:51 PM
I can't test this as I don't have the programme

Option Explicit
'Requires installation of IrfanView
'http://www.irfanview.com/


Sub ConvertPics()
Dim f As String
f = BrowseForFolder("C:\vbax") & "\"
Worksheets(1).Cells(2, 1).Activate
Call Enlist_Directories(f, 1)
End Sub


Sub DoConvert(Pth)
comline = "i_view32.exe " & Pth & "*.png /convert=" & Pth & "*.jpg"
Shell (comline)
End Sub


'http://www.exceltrick.com/formulas_macros/vba-dir-function/
Public Sub Enlist_Directories(strPath As String, lngSheet As Long)
Dim strFldrList() As String
Dim lngArrayMax, x As Long
lngArrayMax = 0
strFn = Dir(strPath & "*.*", 23)
While strFn <> ""
If strFn <> "." And strFn <> ".." Then
If (GetAttr(strPath & strFn) And vbDirectory) = vbDirectory Then
lngArrayMax = lngArrayMax + 1
ReDim Preserve strFldrList(lngArrayMax)
strFldrList(lngArrayMax) = strPath & strFn & "\"
Else
Call DoConvert(strPath)
'ActiveCell.Value = strPath & strFn
'Worksheets(lngSheet).Cells(ActiveCell.Row + 1, 1).Activate
End If
End If
strFn = Dir()
Wend
If lngArrayMax <> 0 Then
For x = 1 To lngArrayMax
Call Enlist_Directories(strFldrList(x), lngSheet)
Next
End If
End Sub


Function BrowseForFolder(Optional OpenAt As Variant) As Variant
'Function purpose: To Browser for a user selected folder.
'If the "OpenAt" path is provided, open the browser at that directory
'NOTE: If invalid, it will open at the Desktop level


Dim ShellApp As Object


'Create a file browser window at the default folder
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)


'Set the folder to that selected. (On error in case cancelled)
On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0


'Destroy the Shell Application
Set ShellApp = Nothing


'Check for invalid or non-entries and send to the Invalid error
'handler if found
'Valid selections can begin L: (where L is a letter) or
'\\ (as in \\servername\sharename. All others are invalid
Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
Case Else
GoTo Invalid
End Select


Exit Function


Invalid:
'If it was determined that the selection was invalid, set to False
BrowseForFolder = False


End Function

YasserKhalil
03-15-2017, 04:37 AM
Thank you very much for great help
I have installed the IrfanView and put the code in module but got error file not found
Is there a reference I have to enable?

snb
03-15-2017, 04:57 AM
To keep it simple:


Sub M_snb()
c00 = "G:\OF\appel.png"
c01 = "G:\OF\appel.jpg"

Shell "F:\Irfanview\i_view32.exe " & c00 & " /convert=" & c01
End Sub

apo
03-15-2017, 05:55 AM
That is beauty in itself... quick stab.. what other files/formats/aps can we/or have you, used this for?

YasserKhalil
03-15-2017, 06:10 AM
Thanks a lot of replies. I could fix the part of File not found by editing the path of the irfan view path itself

comline = "i_view32.exe " & Pth & "*.png /convert=" & Pth & "*.jpg"
In this line how can I add path to destination folder for the output file

YasserKhalil
03-15-2017, 06:19 AM
Thanks a lot for help. I can figure it out by editing that part

Pth & "*.jpg"
I changed pth to the destination path I desire
Best Regards for all of you

snb
03-15-2017, 08:41 AM
@Apo

As far as I can see: all these conversions

18654