Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to pull the names of files from a directory into a csv file with the following:

Get-ChildItem -name | % { [IO.Path]::GetFileNameWithoutExtension($_) } 
                                                  | Export-Csv users.csv

Using '% { [IO.Path]::GetFileNameWithoutExtension($_) }' to display the files with out extensions.

All I get is the following in return:

>>
Length
12
10
13
9
14
18
14
11

Any Ideas?

share|improve this question

1 Answer 1

What does the directory really look like? Guessing the dir does not have dirs named 12,10,13... It does help us help you when we know what you're working with.
Why not just use "basename"?

PS C:\temp\post> ls

    Directory: C:\temp\post


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          3/5/2012   2:55 PM         72 mark.txt
-a---          3/5/2012   2:55 PM         72 mike.txt
-a---          3/5/2012   2:55 PM         72 molly.txt
-a---          3/5/2012   2:57 PM         81 users.csv

PS C:\temp\post> gci | select baseName | export-csv users.csv -noTypeInfo

PS C:\temp\post> gc .\users.csv
"BaseName"
"mark"
"mike"
"molly"
"users"
share|improve this answer
    
using basename worked (i'd not used it before). Thank you :) –  David Munoz Mar 6 '12 at 2:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.