|
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Import des librairies\n",
- "import os\n",
- "\n",
- "# Fonctions\n",
- "def get_total_size(directory):\n",
- " \"\"\"\n",
- " Calcule la somme du poids des fichiers dans un répertoire en Mégaoctets.\n",
- "\n",
- " Args:\n",
- " directory (str): Chemin d'accès au répertoire.\n",
- "\n",
- " Returns:\n",
- " float: Somme du poids des fichiers en Mégaoctets.\n",
- " \"\"\"\n",
- " total_size = 0\n",
- " for root, _, files in os.walk(directory):\n",
- " for filename in files:\n",
- " filepath = os.path.join(root, filename)\n",
- " if os.path.isfile(filepath):\n",
- " filesize = os.path.getsize(filepath)\n",
- " total_size += filesize\n",
- " return total_size / 1024 ** 2 # Convertir en Mégaoctets\n",
- "\n",
- "# Repertoire des donnés\n",
- "data_path = 'D:'\n",
- "\n",
- "# Liste des fichiers\n",
- "data_files = os.listdir(data_path)\n",
- "number_of_files = len(data_files)\n",
- "\n",
- "# Explorer les fichiers\n",
- "print(\"Liste des\", number_of_files, \"fichiers (\", round(get_total_size(data_path), 2), \"Mo ) :\\n\")\n",
- "for item in data_files:\n",
- " print(item)"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.12.1"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
|