Windows 如何创建PowerShell脚本来检查txt文件是否包含超过1行的文本?

Windows 如何创建PowerShell脚本来检查txt文件是否包含超过1行的文本?,windows,powershell,Windows,Powershell,所以我有很多.txt文件。我需要它移动txt文件到一个特定的文件夹,如果他们有超过1行。就是 Text text text Blah blah blah 但如果只是 Text text text 有什么建议吗?这是在Windows XP上,如果有帮助的话。谢谢 编辑:谢谢约翰的努力。找到了一种在PowerShell中实现的方法 # Specify folder name that will contain the filtered .txt files $goodFolder = "Filt

所以我有很多.txt文件。我需要它移动txt文件到一个特定的文件夹,如果他们有超过1行。就是

Text text text
Blah blah blah
但如果只是

Text text text
有什么建议吗?这是在Windows XP上,如果有帮助的话。谢谢

编辑:谢谢约翰的努力。找到了一种在PowerShell中实现的方法

# Specify folder name that will contain the filtered .txt files
$goodFolder = "Filtered"

get-childitem *.txt | foreach ($_) {
$a = get-Content $_.fullname | Measure-Object

# If more than one line is found in text file, move it. Otherwise, leave it alone
If ($a.Count -gt 1) {   # If there is more than one line found in txt file
    Move-Item $_.fullname $goodFolder       # Then move it to a folder with text files with more than 1 line
}
}
注意:最初的问题是如何在.bat文件中执行此操作。 这个答案是对原来问题的解答。它不是powershell解决方案

另存为clines.bat

@echo off
setlocal enabledelayedexpansion
set clines = 0
for /F %%J in (%1) do set /A clines = !clines! + 1
if %clines% LEQ 1 goto finis

rem @echo %1 has %clines% lines
move %1 %2

:finis
endlocal
然后在另一个批处理文件中调用它,该批处理文件将遍历这些文件

@echo off
for %%I in (*.txt) do call clines.bat %%I newfolder

太棒了,非常好用!非常感谢,但是您可能需要编辑代码并将“mov”更改为“move”:)再次感谢!至少对我来说,把“mov”改成“move”对我来说很有效。不知道这是否是因为我使用WinXP?嗯,事实上,我得到了一些奇怪的结果。像有时一样,有些文件仍然保留有超过一行的文本。我知道这有点模糊。。。有什么想法吗?没有,move是正确的,我在测试脚本时注释掉了那一行。我认为for/F循环可能只计算非空行,是吗?