The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a script to bulk move files

Here’s a Python script that lets you bulk move files from one directory to another. This version includes options for filtering by file extension and creating the destination folder if it doesn’t exist:

python
import os import shutil def bulk_move_files(source_dir, destination_dir, file_extension=None): """ Moves all files from source_dir to destination_dir. If file_extension is provided, only files with that extension will be moved. """ if not os.path.exists(source_dir): print(f"Source directory '{source_dir}' does not exist.") return if not os.path.exists(destination_dir): os.makedirs(destination_dir) print(f"Created destination directory '{destination_dir}'.") files_moved = 0 for filename in os.listdir(source_dir): source_file = os.path.join(source_dir, filename) if os.path.isfile(source_file): if file_extension: if not filename.endswith(file_extension): continue destination_file = os.path.join(destination_dir, filename) shutil.move(source_file, destination_file) files_moved += 1 print(f"Moved {files_moved} file(s) from '{source_dir}' to '{destination_dir}'.") # Example usage if __name__ == "__main__": source = "/path/to/source" destination = "/path/to/destination" extension = ".txt" # Set to None to move all files, or ".jpg", ".pdf", etc. bulk_move_files(source, destination, extension)

How to Use

  1. Replace "/path/to/source" with your source directory.

  2. Replace "/path/to/destination" with your target directory.

  3. Set extension to the desired file extension (e.g., .png) or None to move all files.

Let me know if you want a command-line version or integration with a GUI.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About