• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

search all drives for jpg and jpeg files

hello experts, i want a visual basic6 code which searchs all the drives for jpg and jpeg files and put it in mdb file ,
thanks
0
xodos
Asked:
xodos
  • 3
1 Solution
 
gecko_au2003Commented:
Use the file system object to check to see if the file exists.

Here is a URL :

http://www.juicystudio.com/tutorial/asp/files.asp

And I need to go through my PAQ's to give you the other URL that would help you :)
0
 
gecko_au2003Commented:
Here is my other PAQ :

Instead of having the if statement searching for *.*mp3 make it jpg or jpeg , hopefully that helps you. btw it writes the resultes to a text file. You can alter that to your needs :)
0
 
vinnyd79Commented:
Here is an example that requires a reference to microsoft scripting runtime and also a reference to Microsoft ActiveX Data Objects Library:


Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Private Function ShellWait(PathName, Optional WindowStyle As VbAppWinStyle = vbNormalFocus) As Double
Dim hProcess As Long, RetVal As Long
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(PathName, WindowStyle))
    Do
        GetExitCodeProcess hProcess, RetVal
        DoEvents: Sleep 100
    Loop While RetVal = STILL_ACTIVE
End Function

End Sub

Private Sub Command1_Click()
Dim fso, drives, isReady
Set fso = CreateObject("Scripting.FileSystemObject")
Dim FileList As String
Set drives = fso.drives

FileList = Environ("Temp") & "\JpegList.dat"

Dim ff As Integer
ff = FreeFile
Open FileList For Output As #ff: Close #ff

For Each Drive In drives
    isReady = Drive.isReady

    If isReady Then
        ShellWait Environ("Comspec") & " /c dir " & Drive.DriveLetter & ":\*.jpg /s /b >> " & FileList, vbHide
        ShellWait Environ("Comspec") & " /c dir " & Drive.DriveLetter & ":\*.jpeg /s /b >> " & FileList, vbHide
    End If
Next

set fso = Nothing

Dim DataBase As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
DataBase = "C:\MyDataBase.mdb"

' open Database Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & DataBase & "'"
cn.CursorLocation = adUseClient
cn.Open

' open recordset
Set rs = New ADODB.Recordset
rs.Open "Select * From MyTableName", cn, adOpenKeyset, adLockOptimistic

ff = FreeFile
Open FileList For Input As #ff
Do Until EOF(ff)
Line Input #ff, Ln

' add new record to Table
rs.AddNew
rs.Fields("YourFieldName").Value = Ln
rs.Update

DoEvents
Loop
Close #ff

' close recordset
rs.Close
Set rs = Nothing

' close connection
cn.Close
Set cn = Nothing

Kill FileList

End Sub

0
 
xodosAuthor Commented:
hello vinnyd79 , thanks for the code ,
but i want it to create the file CMyDataBase.mdb automatically ,
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now