Categories We Write About

Batch create directories from Excel rows

To batch create directories from Excel rows, you can follow these steps using a script that reads your Excel file and creates folders named after each row entry.

Here’s a detailed way to do it with Python, which is a common approach:


Requirements:

  • Python installed on your machine.

  • pandas library to read Excel.

  • openpyxl if your Excel file is .xlsx.

  • os module to create directories.


Sample Python Script:

python
import os import pandas as pd # Load Excel file excel_file = 'folders.xlsx' # Replace with your Excel file path sheet_name = 'Sheet1' # Replace with your sheet name if different # Read Excel file into DataFrame df = pd.read_excel(excel_file, sheet_name=sheet_name) # Specify the column name that contains folder names folder_column = 'FolderName' # Replace with your actual column header # Base directory where folders will be created (optional) base_dir = 'output_folders' # Replace or set to '.' for current directory # Create base directory if not exist if not os.path.exists(base_dir): os.makedirs(base_dir) # Iterate over each row and create directory for folder_name in df[folder_column]: # Clean folder name string (remove invalid characters) safe_folder_name = "".join(x for x in str(folder_name) if x.isalnum() or x in (" ", "_", "-")).strip() path = os.path.join(base_dir, safe_folder_name) if not os.path.exists(path): os.makedirs(path) print(f"Created: {path}") else: print(f"Already exists: {path}")

How to use:

  1. Prepare your Excel file, e.g., folders.xlsx, with a column named like FolderName listing folder names row-wise.

  2. Update the script’s excel_file, sheet_name, and folder_column to match your Excel file.

  3. Run the script. It will create folders named after each entry inside output_folders directory.


If you want a PowerShell or Batch script instead, or a method without programming, let me know!

Share This Page:

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

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About