Powershell附加到输出 [英] powershell append to output

查看:104
本文介绍了Powershell附加到输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自我学习以提高能力,并且已经收获丰硕,而Google /此网站尚未使我能够找到解决方案。我正在使用来自不同目录的文件列表来编译文本文件,但是在将新数据附加到文件时遇到了麻烦。

I'm 'teaching myself to powershell' and have come a cropper already, and google/this site hasn't enabled me to find a solution. I'm compiling a text file with filelists from different directories, but i'm having trouble appemnding new data to the file.

get-childitem $dir -recurse | % {write-output $_.fullname} >$file

创建我的文件,但随后我想要从下面追加新记录

creates my file, but then i want to APPEND new records from the below

get-childitem $dir2 -recurse | % {write-output $_.fullname} >$file

我都尝试了两个内容和-append,但我无法弄清楚我在做什么,以使其正确。

I've tried both add-content and -append, but I cant figure out what I'm not doing to get it right.

推荐答案

尝试:

get-childitem $dir -recurse | % {write-output $_.fullname} >> $file

(经过测试和工作)

>> 使其始终附加,每次> 都会覆盖一次。



或更改语法以使用 文件外

The double >> makes it append always, a single > overwrites each time.

Or change your syntax to use Out-File

get-childitem $dir -recurse | % {write-output $_.fullname} | out-file -filepath $file -Append

(未测试)

在这种情况下,变量 $ file 必须包含完整路径。像: C:\directory\filename.txt

In this case the variable $file must hold the full path. Like: C:\directory\filename.txt

这篇关于Powershell附加到输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆