View Single Post
Join Date: May 2007
Posts: 45
Reputation: cellus205 is an unknown quantity at this point 
Solved Threads: 1
cellus205 cellus205 is offline Offline
Light Poster

Re: Parsing Zip Files VB.Net

 
0
  #5
Aug 1st, 2008
Can anyone help me convert this VB6 code to get zip filenames to .Net?

  1. Option Explicit
  2.  
  3. Const strStartPath = "C:\"
  4. Const strDestFile = "c:\output.txt"
  5. Const strDestTargetFile = "c:\outputTarget.txt"
  6.  
  7. Dim dicList
  8. dicList = CreateObject("Scripting.Dictionary")
  9. dicList.Add(LCase("mp3"), "")
  10. dicList.Add(LCase("avi"), "")
  11. dicList.Add(LCase("wav"), "")
  12.  
  13.  
  14.  
  15. Dim objFSO, strTempFolder, objDestFile, objDestTargetFile
  16. objFSO = CreateObject("Scripting.FileSystemObject")
  17. strTempFolder = CreateTempFolder()
  18.  
  19. Dim strDest, strDestTarget
  20. strDest = ""
  21. strDestTarget = ""
  22.  
  23. If objFSO.FileExists(strDestFile) Then objFSO.DeleteFile(strDestFile)
  24. If objFSO.FileExists(strDestTargetFile) Then objFSO.DeleteFile(strDestTargetFile)
  25.  
  26. Call TraverseFolder(strStartPath)
  27.  
  28. If objFSO.FolderExists(strTempFolder) Then objFSO.DeleteFolder(strTempFolder)
  29.  
  30.  
  31.  
  32. Sub TraverseFolder(ByVal strFolderPath)
  33. Dim objCurrentFolder, objFile, objFolder
  34. objCurrentFolder = objFSO.GetFolder(strFolderPath)
  35.  
  36. On Error Resume Next
  37.  
  38. For Each objFile In objCurrentFolder.Files
  39. If Not Err() Then
  40. If LCase(objFSO.GetExtensionName(objFile)) = "zip" Then
  41. Call UnZipAndCheckExtension(objFile, strTempFolder)
  42. End If
  43. Else
  44. Err.Clear()
  45. End If
  46. Next
  47.  
  48. For Each objFolder In objCurrentFolder.subFolders
  49. If Not Err() Then
  50. Call TraverseFolder(objFolder.ParentFolder & "\" & objFolder.name)
  51. Else
  52. Err.Clear()
  53. End If
  54. Next
  55.  
  56. On Error GoTo 0
  57. End Sub
  58.  
  59.  
  60. Function UnZipAndCheckExtension(ByVal strZipFile, ByVal strTempFolder)
  61. Const strUNZIPSource = "WZUNZIP.EXE"
  62.  
  63. Dim objFSO, objShell, intRet
  64. objFSO = CreateObject("Scripting.FileSystemObject")
  65. If Not objFSO.FolderExists(strTempFolder) Then objFSO.CreateFolder(strTempFolder)
  66. objShell = CreateObject("WScript.shell")
  67.  
  68. On Error Resume Next
  69. intRet = objShell.Run("""" & strUNZIPSource & """ -o """ & strZipFile & """ """ & strTempFolder & """", _
  70. 0, True)
  71. If Err() Then
  72. On Error GoTo 0
  73. MsgBox(strZipFile & vbLf & Err.Description)
  74. Exit Function
  75. End If
  76. On Error GoTo 0
  77.  
  78. Dim objFolder, objFile
  79. objFolder = objFSO.GetFolder(strTempFolder)
  80.  
  81. strDest = "The following files are found in '" & strZipFile & "':" & vbLf
  82. strDestTarget = "The following special files are found in '" & strZipFile & "':" & vbLf
  83.  
  84. For Each objFile In objFolder.Files
  85. strDest = strDest & "->" & objFSO.GetFileName(objFile) & vbLf
  86.  
  87. If dicList.Exists(LCase(objFSO.GetExtensionName(objFile))) Then
  88. strDestTarget = strDestTarget & "->" & objFSO.GetFileName(objFile) & vbLf
  89. End If
  90.  
  91. objFSO.DeleteFile(objFile)
  92. Next
  93.  
  94. objDestFile = objFSO.OpenTextFile(strDestFile, 8, True)
  95. objDestFile.Write(strDest)
  96. objDestFile.Close()
  97.  
  98. objDestTargetFile = objFSO.OpenTextFile(strDestTargetFile, 8, True)
  99. objDestTargetFile.Write(strDestTarget)
  100. objDestTargetFile.Close()
  101. End Function
  102.  
  103.  
  104. Function CreateTempFolder()
  105. Dim objFSO, strTempFile
  106. objFSO = CreateObject("Scripting.FileSystemObject")
  107. strTempFile = objFSO.GetTempName
  108. strTempFile = Replace(strTempFile, "." & objFSO.GetExtensionName(strTempFile), "")
  109.  
  110. Dim objShell
  111. objShell = CreateObject("WScript.Shell")
  112. CreateTempFolder = Replace(objShell.SpecialFolders("Desktop"), "Desktop", "Local Settings\Temp") & _
  113. "\" & strTempFile
  114. End Function
  115. End Sub
Reply With Quote