Windows Vista Forums

writing out to file
  1. #1


    Braden C. Roberson-Mailloux Guest

    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

  2. #2


    Keith Hill [MVP] Guest

    Re: writing out to file

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

    > 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

  3. #3


    Braden C. Roberson-Mailloux Guest

    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

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

    >> 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

  4. #4


    Braden C. Roberson-Mailloux Guest

    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

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

    >> 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

writing out to file problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to IE or a file won't work Mike H VB Script 4 16 Jun 2009
Writing File to CD ROM SAC VB Script 9 16 May 2009
appending/writing to a file sa VB Script 5 18 Nov 2008
writing output to XML file Nikhil R. Bhandari PowerShell 0 15 Feb 2007
Writing to a file with out-file or export-csv Marco Shaw PowerShell 1 07 Nov 2006