0
1
I'm trying to write a single script on the Windows' Powershell so I can know the total number of pages across various pdf files in the same directory. However, I'm not getting the intended results. Here's my script:
$files = l .
$result = 0
for ($i=0; $i -lt $files.Count; $i++)
{
$fileName = $files[$i].FullName
if ($fileName.EndsWith(".pdf"))
{
pdfinfo.exe $fileName | findstr.exe "Pages:*" | awk '{$result += $2} {print $result}'
}
}
Current results (Individual number of pages):
20
19
10
16
18
14
9
29
24
28
16
30
32
21
13
17
Expected results:
20
39
49
65
83
...
...
...
316
Or just the final value:
316
Thank you very much! I'm not very familiar with the powershell syntax, so I would still like to know why my version isn't working – 136 – 2019-06-08T00:03:53.047
I think
awk '{$result += $2}will append strings, and not do an addition. – LotPings – 2019-06-08T00:18:21.837