Skip to content

TEMPORARY DIRECTORY OPERATIONS

Python
#!/usr/bin/env python3
"""TEMPORARY DIRECTORY OPERATIONS"""
import os, tempfile
with tempfile.TemporaryDirectory() as tmpdir:
    print(f"Created temp dir: {tmpdir}")
    print(f"  Exists: {os.path.exists(tmpdir)}")
    test_file = os.path.join(tmpdir, "test.txt")
    open(test_file, 'w').write("test")
    print(f"  Created file: {os.path.basename(test_file)}")
    print(f"  Files: {os.listdir(tmpdir)}")
print(f"After context: {os.path.exists(tmpdir)}")