Было задание запаковать файл прямо в аксапте. На основе интернета
написал такую функцию. Может кому пригодится.
X++:
boolean zip(str sSourceFile, str sTargetZIPFile)
{
str fzip;
FileName tmpFileName;
FileName tmpZipFileName;
boolean retVal;
AsciiIO file;
int ret;
;
if (!(sSourceFile && sTargetZIPFile))
return retVal;
//Windows vbScript
fzip += '\n'+'Dim oShellApp, oFSO, sSourceFile, sTargetZIPFile, oZipFile, objFolder';
fzip += '\n'+'Set oShellApp = CreateObject(\"Shell.Application\")';
fzip += '\n'+'Set oFSO = CreateObject(\"Scripting.FileSystemObject\")';
fzip += '\n'+'sSourceFile = Wscript.Arguments.Item(0)';
fzip += '\n'+'sTargetZIPFile = Wscript.Arguments.Item(1)';
fzip += '\n'+'\'Write the fileheader for a blank zipfile.';
fzip += '\n'+'Set oZipFile = oFSO.OpenTextFile(sTargetZIPFile, 2, True)';
fzip += '\n'+'oZipFile.Write \"PK\" & Chr(5) & Chr(6) & String(18, Chr(0))';
fzip += '\n'+'oZipFile.Close';
fzip += '\n'+'\'Start copying file into the zip from the source folder.';
fzip += '\n'+'Set objFolder = oShellApp.NameSpace(sTargetZIPFile)';
fzip += '\n'+'if not objFolder is nothing then ';
fzip += '\n'+' objFolder.CopyHere sSourceFile';
fzip += '\n'+' \'Because the copying occurs in a separate process, the script will just continue. Run a DO...LOOP to prevent the function';
fzip += '\n'+' \'from exiting until the file is finished zipping.';
fzip += '\n'+' Do';
fzip += '\n'+' WScript.Sleep 1000';
fzip += '\n'+' Loop While objFolder.Items.Count < 1';
fzip += '\n'+'End If';
tmpFileName = Winapi::getTempFilename(WinApi::getTempPath(),'_zip');
tmpFileName = strreplace(tmpFileName,'.tmp','.vbs');
tmpZipFileName = Winapi::getTempFilename(WinApi::getTempPath(),'_tz');
tmpZipFileName = strreplace(tmpZipFileName,'.tmp','.zip');
// info(strfmt('temp script file: %1',tmpFileName));
// info(strfmt('temp zip file: %1',tmpZipFileName));
if (WinApi::fileExists(tmpFileName))
WinApi::deleteFile(tmpFileName);
if (WinApi::fileExists(tmpZipFileName))
WinApi::deleteFile(tmpZipFileName);
//BP Deviation documented
file = new AsciiIO(tmpFileName,'w');
file.outRecordDelimiter('\n');
if (file)
{
file.write(fzip);
file = null;
ret = Winapi::shellExecute('wscript.exe',strfmt('\"%1\" \"%2\" \"%3\"',tmpFileName,
sSourceFile,
tmpZipFileName),'','',0,true);
//Sleep(1000);
if (ret && Winapi::fileExists(tmpZipFileName))
{
if (WinApi::fileExists(sTargetZIPFile))
WinApi::deleteFile(sTargetZIPFile);
ret = WinApi::moveFile(tmpZipFileName,sTargetZIPFile);
if (!ret)
retVal = true;
}
}
return retVal;
}