Solved

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

Posted on 2011-02-16
2
670 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
A procedure for exporting installed hotfix details of remote computers using powershell
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

14 Experts available now in Live!

Get 1:1 Help Now