2017-01-11 33 views
0
Sub Unzip2() 
Dim FSO As Object 
Dim oApp As Object 
Dim Fname As Variant 
Dim FileNameFolder As Variant 
Dim DefPath As String 
Dim strDate As String 
Dim fileNameInZip As Variant 
'direct = "Y:\DataServices\JohnH\MACRO Domestic\AUTO GLS\REAL ZIPS" 
zippy = Dir(direct & "\*.zip") 
Fname = direct & "\" & zippy 


If Fname = False Then 
    'Do nothing 
Else 
    'Root folder for the new folder. 
    'You can also use DefPath = "C:\Users\Ron\test\" 
    'DefPath = Application.DefaultFilePath 
    'If Right(DefPath, 1) <> "\" Then 
    ' DefPath = DefPath & "\" 
    'End If 

    'Create the folder name 
    'strDate = Format(Now, " dd-mm-yy h-mm-ss") 
    FileNameFolder = direct & "\" 

    'Make the normal folder in DefPath 
    'MkDir FileNameFolder 

    'Extract the files into the newly created folder 
    Set oApp = CreateObject("Shell.Application") 

    'Change this "*.txt" to extract the files you want 
    For Each fileNameInZip In oApp.Namespace(Fname).Items 
     If LCase(fileNameInZip) Like LCase("*.MPU") Then 
      oApp.Namespace(FileNameFolder).CopyHere _ 
        oApp.Namespace(Fname).Items.Item(CStr(fileNameInZip)) 
     End If 
    Next 

    ' MsgBox "You find the files here: " & FileNameFolder 

    On Error Resume Next 
    Set FSO = CreateObject("scripting.filesystemobject") 
    FSO.DeleteFolder Environ("Temp") & "\Temporary Directory*", True 
End If 
'direct = "Y:\Excel\EPICAC\NEW FILES\RESULTS\" 
MkDir (direct & "\" & "Results") 

End Sub 

我使用上面的代碼來提取帶有.mpu文件的zip文件(這實際上只是一個文本文件)然後再打開並讀取一些數據。在記事本中打開.mpu文件後,我的代碼不再可以在zip文件中找到它

但是,我必須從手動讀取MPU中的一些數據,然後在記事本中將其打開。現在,當我進入.zip文件類型不再出現在文件的名稱中,並且代碼無法識別文件中是否有任何MPU。

有沒有辦法將其反轉,以便Windows不會從文件名中刪除.mpu,或者我可以查看文件類型?

回答

-1

我通過更改文件資源管理器設置來修復它以避免隱藏已知的文件路徑。

相關問題