本文介紹PowerShell中如何將文件的內容進行刪除或清空,使用VBScript要先創(chuàng)建FSO,然后再打開文件,再修改文件;PowerShell清空文件只要一句Clear-Content。
所謂清空文件,就是將一個文本文件里面的內容全部刪除,使用記事本等工具打開時,看到的內容是空的,文件的大小也為0KB。我們來看看PowerShell中如何完成清空文件的操作。
名稱
Clear-Content
摘要
刪除項的內容(例如從文件中刪除文本),但不刪除該項。(小編插一句:就是說只刪除文件內空,不刪除文件本身。)
語法
Clear-Content [-LiteralPath] [-Credential] [-Excl
ude ] [-Filter] [-Force] [-Include ] [-Confirm
] [-WhatIf] [-UseTransaction] []
Clear-Content [-Path] [-Credential] [-Exclude ring[]>] [-Filter] [-Force] [-Include ] [-Confirm] [-Wha
tIf] [-UseTransaction] []