| @@ -0,0 +1,5 @@ | |||
| 1 | + | import tempfile, pathlib | |
| 2 | + | ||
| 3 | + | with tempfile.TemporaryDirectory() as d: | |
| 4 | + | tmp = pathlib.Path(d) | |
| 5 | + | # tmp 下做所有中間產物 | |
timmy / Temporary Directory Management
Last active 1 week ago
此組合功能包括一個 Python 腳本和一個 Shell 腳本。Python 腳本用於創建和管理臨時目錄,以存放中間產物;Shell 腳本負責下載指定 URL 的檔案並解壓縮,並在執行完畢後自動清理臨時目錄,確保資源釋放。
timmy revised this gist 11 months ago · c0a80f9
No changes
timmy revised this gist 11 months ago · 3cc85ec
2 files changed, 9 insertions
| @@ -0,0 +1,4 @@ | |||
| 1 | + | tmpdir="$(mktemp -d)" | |
| 2 | + | trap 'rm -rf "$tmpdir"' EXIT | |
| 3 | + | curl -fsSL "$URL" -o "$tmpdir/input.tar.gz" | |
| 4 | + | tar -xzf "$tmpdir/input.tar.gz" -C "$tmpdir" | |