Forum Discussion
HKosova
10 years agoSmartBear Alumni (Retired)
You'll need an external tool like 7-Zip to handle password-protected files, because Windows doesn't have built-in scripting functionality for that. 7-Zip has a standalone command-line version that you can store along with your test assets, or on a shared network drive.
The 7za unzipping syntax is:
The 7za unzipping syntax is:
7za.exe x archive.zip -oOutDir -pPasswordYou can script it like this:
// JScript
function Test()
{
var strArc = "C:\\MyFile.zip";
var strPassword = "password";
var strOutDir = "C:\\MyFolder";
var exitCode = UnzipWithPassword(strArc, strOutDir, strPassword);
if (res != 0)
Log.Error("An error occurred while unpacking. Exit code " + res);
}
function UnzipWithPassword(ArchiveFileName, OutputDir, Password)
{
var str7za = "C:\\Work\\7za.exe"; // Replace with your 7za path
var oShell = Sys.OleObject("WScript.Shell");
var strCommand = aqString.Format("\"%s\" x \"%s\" -o\"%s\" -p\"%s\"", str7za, ArchiveFileName, OutputDir, Password);
return oShell.Run(strCommand, 0, true);
}
Related Content
- 8 months ago
- 3 years ago
- 4 years ago
Recent Discussions
- 2 days ago
- 2 days ago
- 5 days ago