Description
This script reads a CSV file containing source and destination file paths, then copies the files to the specified destinations. It also checks if the destination directories exist and creates them if necessary.
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 (inputfilename) to the destination location (outputfilename). The script skips the first line of the CSV if it contains headers and ensures that the destination directory exists before copying the file.
Parameters
- CsvFilePath [Required]: The path to the CSV file containing the source (inputfilename) and destination (outputfilename) file paths.
Notes
- The script expects the CSV file to have the following columns: inputfilename and outputfilename.
- If the first line of the CSV contains the column headers, it will automatically be skipped during processing.
- If a source file does not exist, the script outputs an error message and continues to the next file.
- If the destination directory does not exist, it will be created automatically before copying the file.
- The script uses Copy-Item to copy files, overwriting any existing files at the destination.
Example
- Open PowerShell as administrator from start menu.
- powershell -ExecutionPolicy Bypass -File [powershellscript] “[csvfilepath]”
- powershell -ExecutionPolicy Bypass -File D:\ copyfile_fromcsv.ps1 “D:\\copy.csv”
Reviews
There are no reviews yet.