所以我有很多.txt文件。如果它们有超过1行,我需要它将txt文件移动到某个文件夹。也就是说,
Text text text
Blah blah blah
但如果只是
,请不要管它Text text text
有关如何执行此操作的任何建议?如果有帮助,这是在Windows XP上。谢谢!
编辑:感谢John的努力。想出了在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
}
}
答案 0 :(得分:0)
这个答案是对原始问题的解决方案。 不是一个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