Nishikawa
06-17-2008, 10:22 PM
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?
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
06-18-2008, 12:23 AM
Try the amended 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
06-18-2008, 06:14 PM
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
06-18-2008, 11:20 PM
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
Nishikawa
06-19-2008, 05:26 PM
The code works but it did not find the zip file.
unclejoe
06-19-2008, 10:13 PM
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
06-20-2008, 01:28 AM
Yup. I tried the same directory with a TXT and RAR file using the same code and it worked.
Swillsy
06-20-2008, 01:39 AM
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
06-20-2008, 01:48 AM
Ok, I will try it and and get back to you guys on Monday. :)
Nishikawa
06-23-2008, 06:15 PM
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?