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

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

问题描述

我正在自学powershell"并且已经有了一个裁剪器,而谷歌/这个网站还没有让我找到解决方案.我正在用来自不同目录的文件列表编译一个文本文件,但是我无法将新数据附加到文件中.

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

我已经尝试了 add-content 和 -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

(经过测试并有效)

>> 使它始终附加,单个 >> 每次都会覆盖.

或者更改您的语法以使用 Out-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天全站免登陆