Solved

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

Posted on 2011-02-16
2
669 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
2 Comments
 
LVL 70

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article will help you understand what HashTables are and how to use them in PowerShell.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now