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 - Using lines in a text file

Reply
 
Old 07-31-2008   #1 (permalink)
tERRY


 
 

Using lines in a text file

I have a text file with names of applications such as Agent, E-Notify, etc. I
read the content of the file with Get-Content. I want to use the application
names to create a path like : "C:\" + $appname. How can I use the output from
get-content? While? ForEach?
--
Terry Edwards

My System SpecsSystem Spec
Old 07-31-2008   #2 (permalink)
Kiron


 
 

Re: Using lines in a text file

If the file contains one app name per line you can pipe the contents to Join-Path's -ChildPath parameter:

gc .\Apps.txt | join-path 'c:\' -ch {$_}

--
Kiron
My System SpecsSystem Spec
Old 07-31-2008   #3 (permalink)
tojo2000


 
 

Re: Using lines in a text file

On Jul 31, 1:14*pm, tERRY <tE...@xxxxxx> wrote:
Quote:

> I have a text file with names of applications such as Agent, E-Notify, etc. I
> read the content of the file with Get-Content. I want to use the application
> names to create a path like : "C:\" + $appname. How can I use the output from
> get-content? While? ForEach?
> --
> Terry Edwards
Foreach should work fine in this situation, since gc grabs one string
per line. Try this:

Get-Content appfile.txt | Foreach {md "C:\$_"}




My System SpecsSystem Spec
Old 08-01-2008   #4 (permalink)
tERRY


 
 

Re: Using lines in a text file

Thanks a bunch. Your suggestion worked like a charm. As a newbie to PS and to
object oriented programming it was getting the pieces in the right relation
that had me stumpted.
--
Terry Edwards


"tojo2000" wrote:
Quote:

> On Jul 31, 1:14 pm, tERRY <tE...@xxxxxx> wrote:
Quote:

> > I have a text file with names of applications such as Agent, E-Notify, etc. I
> > read the content of the file with Get-Content. I want to use the application
> > names to create a path like : "C:\" + $appname. How can I use the output from
> > get-content? While? ForEach?
> > --
> > Terry Edwards
>
> Foreach should work fine in this situation, since gc grabs one string
> per line. Try this:
>
> Get-Content appfile.txt | Foreach {md "C:\$_"}
>
>
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Howto: Add lines of text from a specific point in a text file.. VB Script
get the number of lines in a text file PowerShell
Removing lines from a text file PowerShell
return only certain lines from large text file PowerShell
removing first three lines in a text file 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