Hi
I'm trying to loop through all the files in a directory, including subdirectories and copy anything that has the word 'spec' in it to another location. It work fine until I come across a zip file, which has subdirectories in it. Does anyone know how I loop through files in a subdirectory of a zip file? I've searched on the internet but can't find anything that I can get to work.
Any help gratefully received!
Sub FindZipFileNames(sh, FName)
Dim fileNameInZip, iFileName As String, newFolder As String, nextDir As String, SubF
If FName.items.Count > 0 Then
For Each fileNameInZip In FName.items
If fileNameInZip.isfolder = True Then 'Or LCase(Right(fileNameInZip.Name, 3)) <> "zip" Then
' ' ????
Else
copyFile = False
iFileName = fileNameInZip.Name
If InStr(iFileName, ".") > 0 Then
If Mid(iFileName, Len(iFileName) - 2, 3) = "doc" Or Mid(iFileName, Len(iFileName) - 3, 4) = "docx" Or Mid(iFileName, Len(iFileName) - 3, 4) = "docm" Then
If InStr(UCase(nName), "SPEC") > 0 Then
copyFile = True
cntOther = cntOther + 1
End If
End If
If copyFile = True Then
newFolder = outFolder & Mid(FName, Len(inFolder) + 1, Len(FName) - Len(inFolder)) & ""
If bDirExists(newFolder) = False Then
cntlevels = Len(newFolder) - Len(Replace(newFolder, "", "")) - 1
iPos = InStr(newFolder, "")
For iLevel = 1 To cntlevels
iPos = InStr(iPos + 1, newFolder, "")
nextDir = Mid(newFolder, 1, iPos)
If bDirExists(nextDir) = False Then
MkDir nextDir
End If
Next iLevel
End If
oApp.Namespace(CStr(newFolder)).CopyHere oApp.Namespace(CStr(FName)).items.Item(CStr(fileNameInZip))
End If
End If
End If
Next
End If
Set oApp = Nothing
End Sub
I'm trying to loop through all the files in a directory, including subdirectories and copy anything that has the word 'spec' in it to another location. It work fine until I come across a zip file, which has subdirectories in it. Does anyone know how I loop through files in a subdirectory of a zip file? I've searched on the internet but can't find anything that I can get to work.
Any help gratefully received!
Sub FindZipFileNames(sh, FName)
Dim fileNameInZip, iFileName As String, newFolder As String, nextDir As String, SubF
If FName.items.Count > 0 Then
For Each fileNameInZip In FName.items
If fileNameInZip.isfolder = True Then 'Or LCase(Right(fileNameInZip.Name, 3)) <> "zip" Then
' ' ????
Else
copyFile = False
iFileName = fileNameInZip.Name
If InStr(iFileName, ".") > 0 Then
If Mid(iFileName, Len(iFileName) - 2, 3) = "doc" Or Mid(iFileName, Len(iFileName) - 3, 4) = "docx" Or Mid(iFileName, Len(iFileName) - 3, 4) = "docm" Then
If InStr(UCase(nName), "SPEC") > 0 Then
copyFile = True
cntOther = cntOther + 1
End If
End If
If copyFile = True Then
newFolder = outFolder & Mid(FName, Len(inFolder) + 1, Len(FName) - Len(inFolder)) & ""
If bDirExists(newFolder) = False Then
cntlevels = Len(newFolder) - Len(Replace(newFolder, "", "")) - 1
iPos = InStr(newFolder, "")
For iLevel = 1 To cntlevels
iPos = InStr(iPos + 1, newFolder, "")
nextDir = Mid(newFolder, 1, iPos)
If bDirExists(nextDir) = False Then
MkDir nextDir
End If
Next iLevel
End If
oApp.Namespace(CStr(newFolder)).CopyHere oApp.Namespace(CStr(FName)).items.Item(CStr(fileNameInZip))
End If
End If
End If
Next
End If
Set oApp = Nothing
End Sub