unable to detect zip files (1 Viewer)

Nishikawa

Registered User.
Local time
Today, 05:09
Joined
May 17, 2007
Messages
97
Hi,

I used filesearch to detect zip file but it does not seems to work. Can someone teach me where did I do wrong in my code please?

Code:
    Dim i As Integer
    Dim fs, f
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.getfolder(DatabaseDir)
    
    'Start import
                    With Application.FileSearch
                    .NewSearch
                    .LookIn = f.Path
                    .SearchSubFolders = False
                    .filename = "*.zip"
                    .MatchTextExactly = False
                    .FileType = 1 'msoFileTypeAllFiles
                    .Execute
                                       
                    
                    For i = 1 To .FoundFiles.Count
                    MsgBox .FoundFiles(i)
'                    Dim RaName As String
'                    RaName = Unzip(.FoundFiles(i))
                                                           
                    Next i
                                        
                    
                End With
End Function
 

DCrake

Remembered
Local time
Today, 13:09
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

Try the amended code:

Code:
Public Function FindZipFiles()
Dim StrFileList As String

Set fs = Application.FileSearch
With fs
    .LookIn = CurrentProject.Path
    .FileName = "*.zip"
    If .Execute(SortBy:=msoSortbyFileName, _
            SortOrder:=msoSortOrderAscending) > 0 Then
       If MsgBox("There were " & .foundfiles.Count & _
            " file(s) found. Do you want to view the file names?", vbQuestion + vbYesNo + vbDefaultButton1, "View File Names") = vbYes Then
            For i = 1 To .foundfiles.Count
                 StrFileList = StrFileList & .foundfiles(i) & vbCrLf
            Next i
            MsgBox StrFileList, vbInformation, "Found Files"
        End If
    Else
        MsgBox "There were no files found."
    End If
End With
    
End Function

I assume the DatabaseDir variable is delared elsewhere. In the above example I have used the current mdb path

CodeMaster::cool:
 

Nishikawa

Registered User.
Local time
Today, 05:09
Joined
May 17, 2007
Messages
97
It does not seem to work. I tried with *.RAR and it work.
Do I need to have any add-on for it to be able to find *.ZIP files?
 

DCrake

Remembered
Local time
Today, 13:09
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

When you state it didn't work, do you mean it did not find any zip files or the code was incorrect?

Did it bring up the message box "Cannot find any files"

David
 

unclejoe

Registered User.
Local time
Today, 20:09
Joined
Dec 27, 2004
Messages
190
Your code works on my end. Maybe you need to check the "DatabaseDir". Is it pointed to the correct path?

Hi,
I used filesearch to detect zip file but it does not seems to work. Can someone teach me where did I do wrong in my code please?
 

Nishikawa

Registered User.
Local time
Today, 05:09
Joined
May 17, 2007
Messages
97
Yup. I tried the same directory with a TXT and RAR file using the same code and it worked.
 

Swillsy

Registered User.
Local time
Today, 13:09
Joined
Jun 10, 2008
Messages
68
Hi Nish,
i'm not positive however this does sound like a security issue. I know of other applications/policies that block zip files etc. try using it on a different machine?
 

Nishikawa

Registered User.
Local time
Today, 05:09
Joined
May 17, 2007
Messages
97
Ok, I will try it and and get back to you guys on Monday. :)
 

Nishikawa

Registered User.
Local time
Today, 05:09
Joined
May 17, 2007
Messages
97
I tried using a different computer and it still did not work. I tried using this code from http://www.rondebruin.nl/files/windowsxpunzip.txt

Sub Unzip2()
Dim FSO As Object
Dim oApp As Object
Dim fname
Dim FileNameFolder
Dim DefPath As String

fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _
MultiSelect:=False)
If fname = False Then
'do nothing
Else
DefPath = "C:\Data2\" '<<< Change path
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If

FileNameFolder = DefPath

Set oApp = CreateObject("Shell.Application")
'Copy the files in the newly created folder
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(fname).items

MsgBox "You find the files here: " & FileNameFolder
On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True

Set oApp = Nothing
Set FSO = Nothing
End If
End Sub

Now the problem with the code above is that my VBA does not recognise "Application.GetOpenFilename", stating that: "compile error, method or data member not found"

Is there any library that I need to reference to?
 

Users who are viewing this thread

Top Bottom