| 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 的檔案並解壓縮,並在執行完畢後自動清理臨時目錄,確保資源釋放。
Revision 3cc85ec35d5930a914dfd9f50431cb3c9ab59720
| 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" |
| 5 |
Comments 0
Log in to leave a comment