Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

16 Experts available now in Live!

Get 1:1 Help Now