如何使用 JMP Zip Archive 指令解壓縮在我之前提出的問題中,我詢問是否可以解壓縮檔案。我讀過一篇部落格(使用 FILENAME ZIP 解壓縮並讀取 SAS 中的資料檔案 - SAS Dummy ),但目前我很難使用 JSL 來追蹤它。
我有一個資料夾,裡面有 150 個壓縮資料夾。每個資料夾都有一個裝置名稱,後面跟著訂單分數,然後是日期(即裝置 X_2016_07_20.zip)。我想用設備名稱建立一個新資料夾(我可以開始工作)。我可以打開一個 zip 資料夾並查看其中的所有不同文件,但我不知道如何解壓縮(甚至複製)到新資料夾。有人可以幫我一下嗎?
這是我到目前為止所擁有的:
directory = Pick Directory();
filesInDirectory = Files In Directory( directory );
nFiles = N Items( filesInDirectory ); //get number of zip files in directory
For( i = 1, i <= nFiles, i++,
fileName = filesInDirectory;
pos = Contains( fileName, "_" );
deviceName = Left( fileName, pos - 1 ); //get the device name
subDir = directory || deviceName;
//Create Directory(subDir); //eventually create a new sub directory
za = Open( directory || fileName, zip );
dirlist = za << dir;
Show( dirlist ) // see all contents of zipped folder
;
);
回覆:如何使用 JMP Zip Archive 指令解壓縮我遵循上面的範例程式碼,但是當我嘗試讀取 zip 檔案的內容時,我得到了空資料。
例如,file1.csv 壓縮到 file1.zip,我正在嘗試從 file1.zip 讀取 file1.csv
您能指出我的程式碼有什麼問題嗎?
za = Open( unzip_file_list[1], zip);
dirlist = za << dir;
// below line correctly giving me file1.csv
show(dirlist);
// below two lines correctly gives me full file path.
full_path = directory || dirlist[1];
show(full_path);
// below line returns "Empty()" in log windows.
txt = za << read( full_path);
回覆:如何使用 JMP Zip Archive 指令解壓縮<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />歡迎/感謝,以及後期跟進:載入壓縮數據可能也會有幫助。
回覆:如何使用 JMP Zip Archive 指令解壓縮太感謝了!我絕對把它複雜化了。也很好的解釋。
回覆:如何使用 JMP Zip Archive 指令解壓縮下一行使用 zip 存檔物件 za 從存檔中讀取成員。像這樣的東西:
za = Open( "$desktop\test.zip", zip );
dirlist = za << dir;
Show( dirlist ); // see all contents of zipped folder
// dirlist = {"fft.jmp", "fft2.jsl"};
For( i = 1, i <= N Items( dirlist ), i++,
If( Right( dirlist, 4 ) == ".jmp" /*binary data*/,
blob = za << read( dirlist, Format( blob ) );
Save Text File( "$desktop\deleteme_" || dirlist, blob );
);
If( Right( dirlist, 4 ) == ".jsl" /*text data*/,
text = za << read( dirlist );
Save Text File( "$desktop\deleteme_" || dirlist, text );
);
);
有兩個範例(以粗體顯示),因為 zip 檔案可能包含二進位資料(本例中為 JMP 資料表)或純文字(JMP 腳本)。二進位資料不能儲存在 JSL 字串中,但 BLOB 可以。下一行 saveTextFile 可以理解字串和 BLOB(並且將保存 BLOB 的二進位文件,無論其名稱為何)。您不應該依賴 zip 檔案中成員的順序,特別是如果有人可能編輯/新增/刪除了其中的成員。
(我假設您想要提取成員,而不是將 .zip 檔案複製到另一個 .zip 檔案。您無需打開 zip 檔案即可完成此操作。)
編輯:如果您只是複製文字文件,您也可以使用 BLOB。如果你想處理JSL中的文本,BLOB會讓事情變得更困難。
回覆:如何使用 JMP Zip Archive 指令解壓縮要取得相應的條目,您必須使用 i 作為索引,例如dirlist[i]而不是dirlist
那麼上面的程式碼效果很好。
za = Open( "$desktop\test.zip", zip );
dirlist = za << dir;
For( i = 1, i <= N Items( dirlist ), i++,
blob = za << read( <FONT color="#339966"><STRONG>dirlist[i]</STRONG></FONT>, Format( blob ) );
);
回覆: 如何使用 JMP Zip Archive 指令解壓縮RP = Run Program( Executable( "C:\Program Files\WinRAR\WinRAR.exe" ), Options( {"e -or C:\1\abc.7z C:\2"} ) );