Is there any way to use the CreateObject("Scripting.FileSystemObject") to loop through all subfolders of a particular folder and convert all .bmp files to .jpgs. So far I can only convert files by selecting individual subfolders. Thanks in advance.
Here is the code I am using. It's based on a button click event on a form with two textboxes: Source Folder (SF1) and Output Folder (SF2).
Private Sub ImpWCs_Click()
Dim strSourceDir As String
Dim strDestDir As String
Dim strDestFile As String
Dim strTempName As String
Dim varFiles() As Variant
Dim lngFileCount As Long
Dim srcDirPath As String
Dim destDirPath As String
Dim Fs As Object
Dim Data1 As Database
Dim S1, S2, S3, S4, S5, S6 As String
Set Fs = CreateObject("Scripting.FileSystemObject")
[highlight #73D216]'[SF1] is a textbox on one of my forms poplated with the subfolder path[/highlight]
ChDir Me![SF1]
If GetAttr(Me![SF1]) = vbDirectory Then
strTempName = Dir(Me![SF1], vbDirectory) 'loop through the chosen subfolder [SF1] to store all files in an arrayDo Until Len(strTempName) = 0
If (strTempName <> ".") And (strTempName <> "..") Then
If (GetAttr(Me![SF1] & strTempName) _
And vbDirectory) <> vbDirectory Then 'replace all files with .bmp file extension to .jpg and copy the new files to another folder '[path defined by another form textbox ("OF1")]strDestFile = Replace$(strTempName, ".BMP", ".jpg")FileCopy Me![SF1] & strTempName, Me![OF1] & strDestFile
ReDim Preserve varFiles(lngFileCount)
varFiles(lngFileCount) = strTempName
lngFileCount = lngFileCount + 1
End If
End If
strTempName = Dir()
If Right$(strDestFile, 3) = "jpg" Then 'Insert all the stored filenames and file paths to my Access table (Well Curve Data)DoCmd.RunSQL "INSERT INTO [Well Curve Data] ([FPath],[String Group 1],[String Group 2],[Assay Name],[Well Position],[Observed Call]) Values('" & Me![OF1] & "' + '" & strDestFile & "','" & strDestFile & "','" & SF_splitRight(strDestFile, "- ") & "','" & SF_splitLeft(SF_splitRight(strDestFile, "- "), " -") & "','" & SF_getWord(strDestFile, 1) & "','" & SF_splitLeft(SF_getWord(strDestFile, 6), "(") & "')"
S1 = "Update [Well Curve Data] Set [Observed Call] = 'POS' Where [String Group 1] = '" & strDestFile & "'"
S2 = "Update [Well Curve Data] Set [Observed Call] = 'NEG' Where [String Group 1] = '" & strDestFile & "'"
S3 = "Update [Well Curve Data] Set [Observed Call] = 'NC' Where [String Group 1] = '" & strDestFile & "'"
S4 = "Update [Well Curve Data] Set [Flagged] = -1 Where [String Group 1] = '" & strDestFile & "'"
S5 = "Update [Well Curve Data] Set [Observed Call] = 'FAIL' Where [String Group 1] = '" & strDestFile & "'"
S6 = "Update [Well Curve Data] Set [Observed Call] = 'PASS' Where [String Group 1] = '" & strDestFile & "'"
S7 = "Update [Well Curve Data] Set [Observed Call] = 'FLAG' Where [string Group 1] = '" & strDestFile & "'" 'SQL update statements to update certain blank fields in the [Well Curve Data] table based on populated fields in the tableIf SF_count(strDestFile, "POS") > 0 Then
DoCmd.RunSQL S1
End If
If SF_count(strDestFile, "NEG") > 0 Then
DoCmd.RunSQL S2
End If
If SF_count(strDestFile, "NC") > 0 Then
DoCmd.RunSQL S3
End If
If SF_count(strDestFile, "FLAG") > 0 Then
DoCmd.RunSQL S4
End If
If SF_count(strDestFile, "FAIL") > 0 Then
DoCmd.RunSQL S5
End If
If SF_count(strDestFile, "PASS") > 0 Then
DoCmd.RunSQL S6
End If
If SF_count(strDestFile, "FLAG") > 0 Then
DoCmd.RunSQL S7
End If
End If
Loop
End If
If MsgBox("Import another file set", vbYesNo) = vbNo Then
DoCmd.OpenForm "Well Curve Analysis"
DoCmd.Close
End If
End Sub
perhaps they were all accidently named with the wrong extension? Surely no-one believes changing a file extension physically alters the file type / data structure?
I think you'd be surprised. In the case of BMP to JPG (or the other way around) many, many programs can confuse the issue by happily loading a bmp file that has been renamed as a jpg without complaint or comment (e.g. Paint, or any of the Office programs), thus giving the impression that it really is a jpg file. And the shell will happily (albeit erroneously) tell you that it is a jpeg.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.