回复:從 ZIP 文件的子目錄讀取並保存 txt 文件我在這裡添加了一個 zip 文件夾的示例作為示例。 下面是錯誤信息
dirlist = {"test/12.txt", "test/hello.txt", "test/me/", "test/me/testing.txt", "test/test/", "test/test/mytxtfile.文本文件”};
IO 問題:“mytxtfile”無法以讀寫模式打開。
該系統找不到指定的路徑。
回复:從 ZIP 文件的子目錄讀取並保存 txt 文件我(還)沒有檢查你的腳本哪裡出錯了,但是有一個版本應該保存 txt 文件(由於 For Each() 和 Filter Each() 需要 JMP16+)
Names Default To Here(1);
file_of_interest = "mytxtfile.txt";
zip_path = "$DOWNLOADS\test.zip";
save_path = "$DOWNLOADS\586819.txt";
za = Open(zip_path, "zip");
members_in_zip = za << dir;
// take only .txt files
file_paths_of_interest = Filter Each({members}, members_in_zip,
Ends With(members, file_of_interest);
);
If(N Items(file_paths_of_interest) == 0,
Throw("Not found");
);
// Assume that only one of those files exist
file_path_of_interest = file_paths_of_interest[1];
data = za << read(file_path_of_interest, Format("string"));
Save Text File(save_path, data);
//Open(save_path);

回复:從 ZIP 文件的子目錄讀取並保存 txt 文件關於 zip 文件需要了解的一點是:它們實際上並沒有嵌套的分層目錄結構。 一個 zip 文件的目錄只是一個簡單的字符串名稱列表。 這些名稱可能包含 / 或 \ 字符,一些 zip 文件查看器可能會嘗試將其表示為分層嵌套。 因此,名稱包含的 zip 文件成員我的文本文件名稱中也包含 / 字符,並且在構造此路徑時
save text file(path1 || lst[k] || "_" || dirlist[l] , text);
dirlist 包含“test/test/mytextfile.txt”,並且連接生成的路徑名可能在您的計算機上不存在。
word() 或 words() 函數可能對分隔路徑的各個部分很有用。
從 ZIP 文件的子目錄中讀取並保存 txt 文件你好,
有人可以幫忙嗎。 我嘗試了很多,但仍然失敗。
我嘗試循環遍歷 zip 文件夾列表,以嘗試查找 zip 文件夾子目錄下的特定 txt 文件。當我獲取 zip 文件夾中的文件列表時,我看到 txt 文件為 subdirector/mytxtfile_123.log。 以下是我的腳本,但無法下載 txt 文件。存在 IO 問題,它抱怨“系統找不到指定的路徑”。 我想知道當我獲取文件列表時,是否將“\”翻轉為“/”。 有沒有一種巧妙的方法來獲取子目錄或 zip 中的文件?
path == path where all zip folder located;
path1 == path where txt file going to save;
lst = {the list of the zip folders};
for (k=1, k <=N items(lst), k++,
Try(
za = open(path||lst[k], zip);
dirlist = za << dir;
for (l=1, l<=N Items(dirlist), l++,
If (Contains(dirlist[l], "mytxtfile_"),
text = za << read(dirlist[l]);
save text file(path1||lst[k]||"_"||dirlist[l],text);
);
)
,
print (lst[k] || "fail to open");
Throw();
);
);質量和工藝工程