<jupyter_start><jupyter_text>Examples Example 1: Move A FileAKA cut and paste. Moving files is a fast operation because we are just changing a pointer to the ones and zeros to point to something else. We are not actually pushing bits around disk to make the move happen.The module shutil is filled with all kinds of file handling goodies.In the root of the example directory is a small file. While it is in the root folder, it is simulating being outside the boundaries of the data warehouse environment. Let’s bring it inside by moving it to the In folder.<jupyter_code>import shutil as sh
import os

if not 'script_dir' in globals():
    script_dir = os.getcwd()
    
data_directory = 'data\\'
example_directory = 'BasicFileOpsExample\\'
target_directory = 'In\\'
file_name = 'forestfires.csv'

source_path = os.path.join(script_dir,data_directory,example_directory,file_name)
target_path = os.path.join(script_dir,data_directory,example_directory,target_directory,file_name)

sh.move(source_path, target_path)<jupyter_output><empty_output><jupyter_text>Example 2: Archiving A FileWe are now done processing the file and we need to archive it in case we need to drag it out and reload the system. The process of archiving is multi step. Zip up the file. Move the file to the Archive folder. Blow away the original.Once you run the example, check the Archive folder and the In folder. You should see a zip file in Archive and nothing in the In folder.<jupyter_code>import zipfile as zf
import os

if not 'script_dir' in globals():
    script_dir = os.getcwd()
    
data_directory = 'data\\'
example_directory = 'BasicFileOpsExample\\'
source_directory = 'In\\'
target_directory = 'Archive\\'
file_name = 'forestfires.csv'
archive_name = 'forestfires.zip'

target_path = os.path.join(script_dir,data_directory,example_directory,target_directory,archive_name)
source_path = os.path.join(data_directory,example_directory,source_directory)

archive = zf.ZipFile(target_path, "w")
os.chdir(source_path)
archive.write(file_name)
archive.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0749154180763654, 'fraction_numerical': 0.0009666505558240696, 'mean_word_length': 5.4890282131661445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '2026', 'license': 'MIT', 'n_tokens_mistral': 626, 'n_tokens_neox': 606, 'n_words': 232, 'path': '03 Advanced/20-basic-file-io.ipynb', 'repo_name': 'MassStreetUniversity/tutorial-python', 'size': '2069'}