選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

68 行
1.8 KiB

  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 2,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "# Import des librairies\n",
  10. "import os\n",
  11. "\n",
  12. "# Fonctions\n",
  13. "def get_total_size(directory):\n",
  14. " \"\"\"\n",
  15. " Calcule la somme du poids des fichiers dans un répertoire en Mégaoctets.\n",
  16. "\n",
  17. " Args:\n",
  18. " directory (str): Chemin d'accès au répertoire.\n",
  19. "\n",
  20. " Returns:\n",
  21. " float: Somme du poids des fichiers en Mégaoctets.\n",
  22. " \"\"\"\n",
  23. " total_size = 0\n",
  24. " for root, _, files in os.walk(directory):\n",
  25. " for filename in files:\n",
  26. " filepath = os.path.join(root, filename)\n",
  27. " if os.path.isfile(filepath):\n",
  28. " filesize = os.path.getsize(filepath)\n",
  29. " total_size += filesize\n",
  30. " return total_size / 1024 ** 2 # Convertir en Mégaoctets\n",
  31. "\n",
  32. "# Repertoire des donnés\n",
  33. "data_path = 'D:'\n",
  34. "\n",
  35. "# Liste des fichiers\n",
  36. "data_files = os.listdir(data_path)\n",
  37. "number_of_files = len(data_files)\n",
  38. "\n",
  39. "# Explorer les fichiers\n",
  40. "print(\"Liste des\", number_of_files, \"fichiers (\", round(get_total_size(data_path), 2), \"Mo ) :\\n\")\n",
  41. "for item in data_files:\n",
  42. " print(item)"
  43. ]
  44. }
  45. ],
  46. "metadata": {
  47. "kernelspec": {
  48. "display_name": "Python 3",
  49. "language": "python",
  50. "name": "python3"
  51. },
  52. "language_info": {
  53. "codemirror_mode": {
  54. "name": "ipython",
  55. "version": 3
  56. },
  57. "file_extension": ".py",
  58. "mimetype": "text/x-python",
  59. "name": "python",
  60. "nbconvert_exporter": "python",
  61. "pygments_lexer": "ipython3",
  62. "version": "3.12.1"
  63. }
  64. },
  65. "nbformat": 4,
  66. "nbformat_minor": 2
  67. }