Solved

split file path and names into "fields" and create csv file with list

Posted on 2011-02-16
2
673 Views
Last Modified: 2012-05-11
I am looking to do a directory listing of files and split up the path and file names into fields and create a csv file to import into a document mangement system - so from this dir list:
d:\ap\pcard\fax\mary_1234.tif
d:\ap\pcard\fax\joe_1342.tif
d:\ap\pcard\email\john_2468.pdf
d:\ap\pcard\scan\jill_2222.pdf
I would want this file:
date, source, name, acct#, file path
2/17/2011,fax,mary,1234,d:\ap\pcard\fax\mary_1234.tif
2/17/2011,fax,joe,1342,d:\ap\pcard\fax\joe_1342.tif
2/17/2011,email,john,2468,d:\ap\pcard\email\john_2468.pdf
etc
--
I have parts of this figured out but can't seem to put it all together.
0
Comment
Question by:saladoil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 34909838
Hi there,

Is that directory structure entirely predictable? Never deviates from the format you describe?

And the date in the first field, where'd that come from? I'm going to assume it's last write time for the purposes of writing an example :)

Lots of Regular Expressions here, if the path varies this might fall apart a bit.
Get-ChildItem d:\ap\pcard -Recurse |
  Where-Object { !$_.PsIsContainer } |
  Select-Object `
    @{n='Date';e={ $_.LastWriteTime }},
    @{n='Source';e={ $_.FullName -Replace '^([^\\]*\\){3}|\\.+$' }},
    @{n='Name';e={ (Split-Path $_.FullName -Leaf) -Replace '_.*' }},
    @{n='Acct';e={ $_.FullName -Replace '.*_|\..*' }},
    FullName

Open in new window

Chris
0
 

Author Closing Comment

by:saladoil
ID: 34910353
great - just had to add |export-csv d:\ap\temp\out.csv to wrtie it to a file.
Thanks!
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question