Finding and moving PDF and DOC files to different directories using python

Опубликовано: 04 Август 2026
на канале: CodeMore
4
0

Download this code from https://codegive.com
Certainly! Below is a tutorial that guides you through finding and moving PDF and DOC files to different directories using Python. In this example, we'll use the os and shutil modules to work with the file system.
First, import the required modules – os for interacting with the operating system and shutil for file operations.
Specify the source directory where your PDF and DOC files are located. Also, define the destination directories where you want to move the files based on their types.
Replace /path/to/source, /path/to/destination/pdf, and /path/to/destination/doc with the actual paths of your source and destination directories.
Use the os.listdir() function to get the list of files in the source directory. Filter the files based on their extensions (PDF and DOC).
Now, iterate through the lists of PDF and DOC files and move them to their respective destination directories using shutil.move().
Save your script with a .py extension (e.g., move_files.py) and run it using a Python interpreter:
This script will find all PDF and DOC files in the source directory and move them to the specified PDF and DOC destination directories, respectively.
This tutorial provides a basic example of how to find and move PDF and DOC files using Python. You can modify and extend the script based on your specific requirements.
ChatGPT