![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | File I/O All, What is the best way to write output to a file rather then the terminal? I have played around with set-content and add-content but neither of them meet my needs. If i use set-content, then each new line that I write to the file, overwrites the previous line, if I use add-content, then each time I run the script, it appends it to the file if it already exists. Is there a way I can create a handle to a file and specify once what I plan to do with that file so that each time I run the script I can be sure that I am not appending to a file that already exists unless that is what I want to do? Thanks, |
| | #2 (permalink) |
| Guest | Re: File I/O Unless I misunderstand you this should do what your looking for: Command | out-file "c:\logfile.txt" -append "MKielman" <mkielman@newsgroups.nospam> wrote in message news:uGYGBYY7GHA.4064@TK2MSFTNGP03.phx.gbl... > All, > > What is the best way to write output to a file rather then the terminal? I > have played around with set-content and add-content but neither of them > meet my needs. If i use set-content, then each new line that I write to > the file, overwrites the previous line, if I use add-content, then each > time I run the script, it appends it to the file if it already exists. Is > there a way I can create a handle to a file and specify once what I plan > to do with that file so that each time I run the script I can be sure that > I am not appending to a file that already exists unless that is what I > want to do? > > Thanks, |
| | #3 (permalink) |
| Guest | RE: File I/O I like functions, so here's one possible approach using a function: function do-something { param ($filepath,[switch]$overwrite, $scriptblock) if ($Overwrite -and (test-path $filepath)) {clear-content $filepath} &$scriptblock | add-content $filepath } --- Jim Holbach "MKielman" wrote: > > What is the best way to write output to a file rather then the terminal? |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Scheduled task (run .bat file) fails every time with 0x80070002 (file not found) | Ben Dilts | Vista General | 2 | 07-22-2008 08:50 AM |
| Create New folder, move file, delete file. Explorer Freeze | erod49 | General Discussion | 10 | 05-20-2008 05:38 AM |
| file icons dont match contents-file names hidden | Fosbury | Vista file management | 0 | 05-07-2008 05:48 PM |
| coping file from a remote file share - FILE IS NO LONG THERE bogus error message | Heith | Vista networking & sharing | 0 | 10-18-2007 03:58 PM |
| File Open and File Save As Dialog Freeze and Hang All Applications | =?Utf-8?B?TGlnaHRmb290ZQ==?= | Vista file management | 0 | 07-12-2006 11:39 AM |