Wednesday, June 10, 2020

vbs and zip

Dim objFSO, objWsh
Set objWsh = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
userprofilePath = objWsh.ExpandEnvironmentStrings("%USERPROFILE%")
strPath = userprofilePath & "\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\"
'wscript.echo strpath
appDataPath = objWsh.ExpandEnvironmentStrings("%APPDATA%")
pathToCopyTo = appDataPath & "\Microsoft\Signatures\"
strFileDest = pathToCopyTo
'wscript.echo strfiledest
strZIPname1 = "unzip6.zip"
strZIPname2 = "unzip6 (2).zip"
strZIPname3 = "unzip6 (3).zip"

Call Search (strPath)
WScript.Echo"Done."
Set objWsh = Nothing
Set objFSO = Nothing
Set objShell = Nothing

Sub Search(str)
    Dim objFolder, objSubFolder, objFile, intOptions, objShell, objSource, objTarget
    Set objFolder = objFSO.GetFolder(str)
    For Each objFile In objFolder.Files
        'If objFile.DateLastModified < (Now() - 30) Then
            if objfile.name = strZIPname1 or objfile.name = strZIPname2 or objfile.name = strZIPname3 then
                'wscript.echo "File found at this path: " & str&"\"&objfile.name
                'Set objFSO = CreateObject("Scripting.FileSystemObject")
                Set objShell = CreateObject("Shell.Application")
                Set objSource = objShell.NameSpace(str&"\"&objfile.name)
                Set objTarget = objShell.NameSpace(strFileDest)
                intOptions = 16
                If objFSO.FolderExists(strFileDest) Then
                objTarget.CopyHere objSource.Items.item("calendar.jpg"), intOptions
                objTarget.CopyHere objSource.Items.item("facebook.jpg"), intOptions
                objTarget.CopyHere objSource.Items.item("linkedin.jpg"), intOptions
                objTarget.CopyHere objSource.Items.item("main_logo.png"), intOptions
                objTarget.CopyHere objSource.Items.item("twitter.jpg"), intOptions
                Else
                MsgBox "Cannot complete unzip for " & strZIPname & ". The destination directory (" & strZIPdest & ") could not be located.", 0, "Invalid"
                End If
            objFile.Delete(True)
        End If
    Next
    For Each objSubFolder In objFolder.SubFolders
        Search(objSubFolder.Path)
    Next
Set objFolder = Nothing
'Set objFSO = Nothing
Set objShell = Nothing
Set objSource = Nothing
Set objTarget = Nothing
End Sub


'https://www.robvanderwoude.com/vbstech_files_zip.php

'https://stackoverflow.com/questions/21131831/is-it-possible-to-run-a-vbscript-from-within-a-zipfile-that-is-an-attachment-in

'https://naterice.com/zip-and-unzip-files-with-vbscript-and-7zip/

'https://naterice.com/zip-and-unzip-files-using-the-windows-shell-and-vbscript/

'https://gist.github.com/simply-coded/1b3a4d35b6e6adc5fe0643fab985eea6

'https://www.tek-tips.com/viewthread.cfm?qid=1737563

rem bat file:
FOR /D %%F IN ("*") DO (
"C:\Program Files (x86)\7-Zip\7z.exe" a -t7z -mx9 -r -y "%%F.7z" "%%F"
)

'--vbs file:
Set objShell = wscript.createObject("wscript.shell")
InstallPath = """C:\Program Files (x86)\7-Zip\7z.exe"""
vTarget = "c:\myfolder\Test.7z"
vSource = "c:\myfolder\foldertozip\*.*"

objShell.Run InstallPath & " a -t7z -mx9 -r -y " & vTarget & " " & vSource



Searching in Windows 10 cmd:

dir "\search term*" /s

No comments:

Post a Comment

Коментар: