문제
전체 폴더를 단일 ".zip"파일로 압축해야합니다.
해결책
ZipArchive 객체를 생성하기 위해 파일을 압축하는 JMP의 내장 지원을 사용하십시오. ZipArchive 객체가 있으면 압축되지 않은 파일의 BLOB 표현을 ".zip"파일에 쓸 수 있습니다.
/*
Arguments:
folderToZip - "path" - path to the folder you want to compress
zipFileLoc - "path" - path to the output zip file
overwriteFile - <0|1> - do you want to overwrite an existing file. default is 0
recursive - <0|1> - do you want all files in the folder or just top leve. default is 1
*/
zipFolder = Function( {folderToZip, zipFileLoc, overwriteFile = 0, recursive = 1},
{Default Local},
// Convert the filepath to the OS and add a trailing slash if one is missing
If( Host is( "Windows" ),
folderToZip = Convert File Path( folderToZip, "Windows" );
zipFileLoc = Convert File Path( zipFileLoc, "Windows" );
If( Substr( folderToZip, -1 ) != "\",
folderToZip = Concat( folderToZip, "\" )
);
,
folderToZip = Convert File Path( folderToZip, "posix" );
zipFileLoc = Convert File Path( zipFileLoc, "posix" );
If( Substr( folderToZip, -1 ) != "/",
folderToZip = Concat( folderToZip, "/" )
);
);
// Check to see if the file exst
If( File Exists( zipFileLoc ),
Match( overwriteFile,
0, // if we should not overwrite, write to the log and return 0
Write( "\!NFile already exists" );
Return( 0 );
,
1, // else just delete the existing file
Delete File( zipFileLoc ),
);
);
// create the zipfile and ZipArchive object (za)
za = Open( zipFileLoc, zip );
// get our list of files to compress, based on recursive setting
If( recursive == 1,
dirlist = Files In Directory( folderToZip, "recursive" ),
dirlist = Files In Directory( folderToZip )
);
// loop through each file
For( iFile = 1, iFile <= N Items( dirlist ), iFile++,
// read in the uncompressed file as a blob
tmpBlob = Load Text File( folderToZip || dirlist[iFile], blob );
// write compressed file to the ZipArchive object
za << Write( dirlist[iFile], tmpBlob );
);
Return( 1 );
);
토론
몇 가지 추가 기능에서이 함수의 변형을 사용했습니다. 바라기를 이것은 당신이 당신의 파일을 압축하는 것을 시작할 것입니다!
참고 사항
JSL 구문 참조> JSL 메시지> 기타 객체> Zip 아카이브
스크립팅 색인> ZipArchive