|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Shutil Module:\n", |
| 8 | + "### Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories." |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "metadata": {}, |
| 14 | + "source": [ |
| 15 | + "## The shutil.copy() function copies a single file, whereas shutil.copytree() copies the entire folder with all its contents." |
| 16 | + ] |
| 17 | + }, |
| 18 | + { |
| 19 | + "cell_type": "markdown", |
| 20 | + "metadata": {}, |
| 21 | + "source": [ |
| 22 | + "## The shutil.move() function is used for renaming files, as well as moving them." |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "markdown", |
| 27 | + "metadata": {}, |
| 28 | + "source": [ |
| 29 | + "## shutil functions will permanently delete files and folders whereas send2trash delete functions will move a file or folder to the recycle bin." |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "markdown", |
| 34 | + "metadata": {}, |
| 35 | + "source": [ |
| 36 | + "## The zipfile.ZipFile() function is same as open function; the first parameter is the filename, and the second parameter is the mode to open the .zip file like read, write, or append." |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": 12, |
| 42 | + "metadata": {}, |
| 43 | + "outputs": [ |
| 44 | + { |
| 45 | + "name": "stdout", |
| 46 | + "output_type": "stream", |
| 47 | + "text": [ |
| 48 | + "location: C:\\Users\\91706\\Desktop\\docs\\Akash Bertila LOR.jpg\n", |
| 49 | + "location: C:\\Users\\91706\\Desktop\\docs\\Akash Wilson LOR.jpg\n" |
| 50 | + ] |
| 51 | + } |
| 52 | + ], |
| 53 | + "source": [ |
| 54 | + "import os, shutil\n", |
| 55 | + "\n", |
| 56 | + "def moveFileJPG(folder): \n", |
| 57 | + " for root, dirs, files in os.walk(folder): \n", |
| 58 | + " for file in files: \n", |
| 59 | + " if file.endswith('.jpg'):\n", |
| 60 | + " image_path=os.path.join(root,file) # get the path location of each jpeg image.\n", |
| 61 | + " print('location: ',image_path)\n", |
| 62 | + " shutil.copy(image_path, r'C:\\\\Users\\\\91706\\\\Documents\\\\cpy-jpg')\n", |
| 63 | + "\n", |
| 64 | + "\n", |
| 65 | + "moveFileJPG('C:\\\\Users\\\\91706\\\\Desktop\\\\docs')" |
| 66 | + ] |
| 67 | + } |
| 68 | + ], |
| 69 | + "metadata": { |
| 70 | + "kernelspec": { |
| 71 | + "display_name": "Python 3", |
| 72 | + "language": "python", |
| 73 | + "name": "python3" |
| 74 | + }, |
| 75 | + "language_info": { |
| 76 | + "codemirror_mode": { |
| 77 | + "name": "ipython", |
| 78 | + "version": 3 |
| 79 | + }, |
| 80 | + "file_extension": ".py", |
| 81 | + "mimetype": "text/x-python", |
| 82 | + "name": "python", |
| 83 | + "nbconvert_exporter": "python", |
| 84 | + "pygments_lexer": "ipython3", |
| 85 | + "version": "3.8.5" |
| 86 | + } |
| 87 | + }, |
| 88 | + "nbformat": 4, |
| 89 | + "nbformat_minor": 4 |
| 90 | +} |
0 commit comments