CSV-Driven File Copier with Directory Creation using PowerShell Script

$0.00

Category:

Product Overview

The CopyFilesFromCsv.ps1 script processes a CSV file containing two columns: inputfilename and outputfilename. It copies each file specified in the CSV from the source location to the destination location. This script is ideal for batch file operations in eDiscovery workflows, document migrations, and organized file distribution tasks. The script automatically handles directory creation, skips CSV headers, and provides clear error reporting for missing files.

Key Features

📋

CSV-Driven Automation

Process hundreds or thousands of file copy operations from a single CSV file

📁

Auto-Directory Creation

Automatically creates destination directories if they don’t exist

🔄

Smart Header Detection

Automatically skips CSV header rows during processing

⚠️

Error Handling

Continues processing even if some files are missing, with clear error messages

Parameters

📄

CsvFilePathRequired

String Parameter

The path to the CSV file containing the source (inputfilename) and destination (outputfilename) file paths. This CSV file drives the entire copy operation, with each row representing a single file copy task.

Type String (File Path)
Format Absolute or relative path to CSV file
Required Columns inputfilename and outputfilename
Header Row Automatically detected and skipped if present
Example CSV File Paths

Local File: D:\copy.csv
Network Path: \\server\share\filelist.csv
Relative Path: .\config\copy-list.csv

📋 CSV Format Requirements

Required Columns

The CSV file must contain exactly two columns with the following names:

inputfilename

The source file path (where to copy from)

C:\Source\document.pdf

outputfilename

The destination file path (where to copy to)

D:\Backup\document.pdf

Sample CSV File Structure

inputfilename,outputfilename
C:\Documents\report.docx,D:\Archive\2024\report.docx
C:\Documents\invoice.pdf,D:\Archive\2024\invoice.pdf
\\server\files\data.xlsx,E:\Backup\data.xlsx
C:\Images\photo.jpg,D:\Photos\2024\photo.jpg
💡 Header Row Handling

If your CSV file includes a header row (as shown above), the script will automatically detect and skip it. You can also create CSV files without headers—the script will process all rows in that case.

🔧 How the Script Works

1

Read CSV File
The script reads the CSV file from the specified path and loads all rows containing file path pairs.

2

Skip Header Row
If the first row contains column headers (inputfilename, outputfilename), it is automatically skipped to avoid processing header text as file paths.

3

Validate Source Files
For each row, the script checks if the source file exists. If a source file is missing, an error message is displayed and the script continues to the next row.

4

Create Destination Directories
Before copying, the script checks if the destination directory exists. If not, it automatically creates all necessary parent directories in the path.

5

Copy Files
The script uses Copy-Item to copy each file from the source to destination. If a file already exists at the destination, it will be overwritten.

📌 Important Notes

✓ CSV Structure

The script expects the CSV file to have exactly two columns: inputfilename and outputfilename. Column order matters—source must be first, destination second.

✓ Header Row Handling

If the first line of the CSV contains column headers, it will automatically be skipped during processing. Headers are optional but recommended for clarity.

⚠️ Missing Source Files

If a source file does not exist, the script outputs an error message and continues to the next file in the CSV. The script will not stop processing due to individual file errors.

✓ Automatic Directory Creation

If the destination directory does not exist, it will be created automatically before copying the file. All necessary parent directories in the path will also be created.

⚠️ File Overwrite Behavior

The script uses Copy-Item to copy files, which will overwrite any existing files at the destination without prompting. Ensure destination paths are correct before running the script.

💡 Usage Examples

⚠️ Important Prerequisite

Open PowerShell as Administrator from the Start menu before running these commands.

Example 1: Basic Syntax Template

General command structure for running the script:


powershell -ExecutionPolicy Bypass -File [powershellscript] "[csvfilepath]"
Note: Replace the bracketed values with your actual script and CSV file paths

Example 2: Copy Files from Local CSV

Process a CSV file located on your local drive:


powershell -ExecutionPolicy Bypass -File D:\copyfile_fromcsv.ps1 "D:\copy.csv"
What this does: Processes all file copy operations listed in D:\copy.csv

Example 3: Process CSV from Network Location

Run the script with a CSV file stored on a network share:


powershell -ExecutionPolicy Bypass -File C:\Scripts\copyfile_fromcsv.ps1 "\\server\share\migration-list.csv"
What this does: Processes file copies from a CSV stored on a network location

Example 4: eDiscovery Document Migration

Use for organized eDiscovery document transfers:


powershell -ExecutionPolicy Bypass -File C:\Scripts\copyfile_fromcsv.ps1 "E:\Production\export-filelist.csv"
What this does: Copies production documents according to the export file list for organized delivery

Example 5: Sample CSV Content for Testing

Create a CSV file with this content to test the script:

inputfilename,outputfilename
C:\Temp\document1.pdf,D:\Archive\docs\document1.pdf
C:\Temp\spreadsheet.xlsx,D:\Archive\data\spreadsheet.xlsx
C:\Temp\presentation.pptx,D:\Archive\presentations\presentation.pptx
Usage: Save this content as copy.csv and run the script with this CSV file path

Why Use This Script?

Batch Processing: Copy hundreds or thousands of files in one operation from a simple CSV file

Error Resilience: Continues processing even if individual files are missing or inaccessible

Automation Ready: Easy to integrate into larger workflows and automated processes

Organized Structure: Automatically creates directory structures based on destination paths

eDiscovery Compatible: Perfect for production exports, document migrations, and file organization

Simple Format: Uses standard CSV files that can be created in Excel or any spreadsheet application

💼 Common Use Cases

📁 eDiscovery Production

Copy responsive documents from review platform exports to organized production folders for client delivery.

🔄 Document Migration

Migrate files from legacy systems to new storage locations while maintaining organized folder structures.

💾 Backup Operations

Create selective backups of important files based on a predefined list without copying entire directories.

📤 File Distribution

Distribute specific files to multiple locations or reorganize files across different directory structures.

💻 System Requirements
  • Windows operating system (Windows 7/Server 2008 or later)
  • PowerShell 3.0 or higher
  • Administrator privileges for running the script
  • Valid CSV file with inputfilename and outputfilename columns
  • Read access to source file locations
  • Write access to destination directories
  • Sufficient disk space at destination locations

Reviews

There are no reviews yet.

Be the first to review “CSV-Driven File Copier with Directory Creation using PowerShell Script”

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

Shopping Cart
  • Your cart is empty.