Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - writing out to file

Reply
 
Old 05-16-2008   #1 (permalink)
Braden C. Roberson-Mailloux


 
 

writing out to file

Hello everyone;

I'm writing a one-line to take the recursive contents of a directory and
write its contents out to file with send prefixed in front of the $_.name
object.

It goes like this:

dir -recurse | ForEach-Object { write-host send $_name } | Out-File
ftp_batch.txt

but it does not write to file.

Any pointers?



My System SpecsSystem Spec
Old 05-16-2008   #2 (permalink)
Keith Hill [MVP]


 
 

Re: writing out to file

"Braden C. Roberson-Mailloux" <bray@xxxxxx> wrote in message
news:#Z$oFd5tIHA.1220@xxxxxx
Quote:

> Hello everyone;
>
> I'm writing a one-line to take the recursive contents of a directory and
> write its contents out to file with send prefixed in front of the $_.name
> object.
>
> It goes like this:
>
> dir -recurse | ForEach-Object { write-host send $_name } | Out-File
> ftp_batch.txt
>
> but it does not write to file.
>
> Any pointers?
First you don't want to use Write-Host since that writes directly to the
host's UI and can't be redirected to a file using Out-File or >. You want
to use Write-Output instead. Second, you are missing a '.' between $_ and
name. Finally since you want to put the "send" and the name on the same line
you should do this:

dir -r | foreach { "send $($_.name)" } > ftp_batch.txt

Note that when PowerShell sees a string like "send $($_.name)" it implicitly
outputs it just as if you had written - write-output "send $($_.name)".

--
Keith

My System SpecsSystem Spec
Old 05-18-2008   #3 (permalink)
Braden C. Roberson-Mailloux


 
 

Re: writing out to file

Thanks for the response, Keith. I'll give this a shot and report back.

"Keith Hill [MVP]" <r_keith_hill@xxxxxx_no_spam_I> wrote in message
news:8882F6B5-7458-4648-9510-BB6AE0C7C670@xxxxxx
Quote:

> "Braden C. Roberson-Mailloux" <bray@xxxxxx> wrote in message
> news:#Z$oFd5tIHA.1220@xxxxxx
Quote:

>> Hello everyone;
>>
>> I'm writing a one-line to take the recursive contents of a directory and
>> write its contents out to file with send prefixed in front of the $_.name
>> object.
>>
>> It goes like this:
>>
>> dir -recurse | ForEach-Object { write-host send $_name } | Out-File
>> ftp_batch.txt
>>
>> but it does not write to file.
>>
>> Any pointers?
>
> First you don't want to use Write-Host since that writes directly to the
> host's UI and can't be redirected to a file using Out-File or >. You want
> to use Write-Output instead. Second, you are missing a '.' between $_ and
> name. Finally since you want to put the "send" and the name on the same
> line you should do this:
>
> dir -r | foreach { "send $($_.name)" } > ftp_batch.txt
>
> Note that when PowerShell sees a string like "send $($_.name)" it
> implicitly outputs it just as if you had written - write-output "send
> $($_.name)".
>
> --
> Keith

My System SpecsSystem Spec
Old 05-18-2008   #4 (permalink)
Braden C. Roberson-Mailloux


 
 

Re: writing out to file

It works. Awesome.
"Keith Hill [MVP]" <r_keith_hill@xxxxxx_no_spam_I> wrote in message
news:8882F6B5-7458-4648-9510-BB6AE0C7C670@xxxxxx
Quote:

> "Braden C. Roberson-Mailloux" <bray@xxxxxx> wrote in message
> news:#Z$oFd5tIHA.1220@xxxxxx
Quote:

>> Hello everyone;
>>
>> I'm writing a one-line to take the recursive contents of a directory and
>> write its contents out to file with send prefixed in front of the $_.name
>> object.
>>
>> It goes like this:
>>
>> dir -recurse | ForEach-Object { write-host send $_name } | Out-File
>> ftp_batch.txt
>>
>> but it does not write to file.
>>
>> Any pointers?
>
> First you don't want to use Write-Host since that writes directly to the
> host's UI and can't be redirected to a file using Out-File or >. You want
> to use Write-Output instead. Second, you are missing a '.' between $_ and
> name. Finally since you want to put the "send" and the name on the same
> line you should do this:
>
> dir -r | foreach { "send $($_.name)" } > ftp_batch.txt
>
> Note that when PowerShell sees a string like "send $($_.name)" it
> implicitly outputs it just as if you had written - write-output "send
> $($_.name)".
>
> --
> Keith

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Writing to IE or a file won't work VB Script
Writing File to CD ROM VB Script
Problem Writing file to CD .NET General
writing output to XML file PowerShell
Writing to a file with out-file or export-csv PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46