INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Powershell Script - Create Separate CSV files Based on Directory Contents

Powershell Script - Create Separate CSV files Based on Directory Contents

Powershell Script - Create Separate CSV files Based on Directory Contents

(OP)
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!

RE: Powershell Script - Create Separate CSV files Based on Directory Contents

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close