Ik heb een probleem met het gebruik van 7Zip in een VBscript. Met de commandline versie (7za.exe) probeer ik een bestand in te pakken. Handmatig via de cli gaat dit goed, tevens lukt het met een constante waarde in mijn script:
Het lukt mij echter niet om bestanden in te pakken welke mijn filesearch routine genereert. Ik heb echter geen idee wat hier precies fout gaat, wellicht spatiegebruik / juiste quotes gebruik in WShell.Exec string.
Source en target printen beide het volledige pad inclusief spaties en de juiste bestandsnamen (photo.jpg en photo.jpg.7z
Probleem code:
Voor de volledigheid hierbij mijn complete functie (code voor extensie filtering is weggelaten tbv leesbaarheid):
VBScript:
1
2
3
4
| 'MANUAL 7ZIP TEST CODE - WORKS Set wshShell = CreateObject("WScript.Shell") iReturn = wshShell.Run("""c:\Program Files\7-Zip\7za.exe"" a ""c:\Documents and Settings\Administrator\Desktop\Files\photo.jpg.7z"" ""c:\Documents and Settings\Administrator\Desktop\Files\photo.jpg""", 0, True) 'END OF 7ZIP TEST CODE. |
Het lukt mij echter niet om bestanden in te pakken welke mijn filesearch routine genereert. Ik heb echter geen idee wat hier precies fout gaat, wellicht spatiegebruik / juiste quotes gebruik in WShell.Exec string.
Source en target printen beide het volledige pad inclusief spaties en de juiste bestandsnamen (photo.jpg en photo.jpg.7z
Probleem code:
VBScript:
1
2
3
4
5
6
7
| strFile = objFile.Path strArch = strFile & ".7z" WScript.Echo "source", strFile WScript.Echo "target", strArch set objExec = WShell.Exec(""" & strCommand & "" & a & "" & strArch & "" & "" & strFile & """, 1 ,true) |
Voor de volledigheid hierbij mijn complete functie (code voor extensie filtering is weggelaten tbv leesbaarheid):
VBScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| 'Recursive Filesearch Subroutine. 'IN - Drive or Path Sub Search(sPath) 'Loop through each file in the sPath folder. For Each objFile In sPath.Files strFile = objFile.Path strArch = strFile & ".7z" strCommand = "c:\program files\7-zip\7za.exe" WScript.Echo "source", strFile WScript.Echo "target", strArch set WShell = CreateObject("WScript.Shell") set objExec = WShell.Exec(""" & strCommand & "" & a & "" & strArch & "" & "" & strFile & """, 1 ,true) End If Next 'Find EACH SUBFOLDER. For Each subFolder In sPath.SubFolders On Error Resume Next 'Call the Search subroutine to start the recursive search on EACH SUBFOLDER. If Err.number = 0 Then Search objFSO.GetFolder(subFolder.Path) End If Next End Sub |
This signature has been taken down by the Dutch police in the course of an international lawenforcement operation.