Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Powershell Script - Create Separate CSV files Based on Directory Contents

Status
Not open for further replies.

BuckBMD

MIS
Mar 15, 2001
13
US
I need some help in creating separate CSV files based on the contents of a directory.
The CSV would contain the designated substring as one column, and the complete path and filename in a second column. No quotes as text qualifiers.

Assume the folder name = C:\Temp\Images
The content is as follows:

123456_A.tif
123456_B.tif
123456_C.tif
123456_D.tif
.....
234567_A.tif
234567_B.tif
.....
345678_A.tif
345678_B.tif
345678_C.tif

I need to end up with three (3) separate CSV files, based on a substring of the filename. (In this case, the first 6 characters.)

Example;

"123456.csv" would contain

123456,C:\Temp\Images\123456_A.tif
123456,C:\Temp\Images\123456_B.tif
123456,C:\Temp\Images\123456_C.tif
123456,C:\Temp\Images\123456_D.tif

"234567.csv" would contain

234567,C:\Temp\Images\234567_A.tif
234567,C:\Temp\Images\234567_B.tif

"345678.csv" would contain

345678,C:\Temp\Images\345678_A.tif
345678,C:\Temp\Images\345678_B.tif
345678,C:\Temp\Images\345678_C.tif

I've used Powershell before, but this specific task is over my head. If someone would be kind enough to get me started, I can probably refine it and get it working as required.

Any assistance would be greatly appreciated. Thanks!
 
Please disregard this initial post.

I ended up creating one whole CSV containing the prefix of the file name, and the complete path and file. I then looped through that file and created separate CSV based on the prefix of the file name, which happened to be first value in each line of the larger CSV. The speed is very quick. Because this is an automated process now (firing every 10 minutes), the speed is suitable for our requirements.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top