Jonathan003 wrote on 08/28/23 at 18:38:24:
I wonder if it is possible somehow to clean multiple pgn's in a folder all at once?
Yes, and pgn-extract in a script is a good way to do it.
Jonathan003 wrote on 08/28/23 at 18:38:24:
I want a script to clean multiple pgn files in a folder, and overwrite the original pgn files with the cleaned ones, in one go.
What you are asking for is called "in-place editing". pgn-extract cannot do it, but a script can do it using a temporary file. However, it is generally considered a bad idea:
https://backreference.org/2011/01/29/in-place-editing-of-files/index.html In your scenario, in-place editing is definitely a bad idea because all "unclean" parts of the pgn(s) will be lost, and in a worst case you may end up with an entire folder of zero-byte pgns, without any easy way to recover the originals.
That said, I wrote you a script that does most of what you asked. For any one folder you give to the script, it will run pgn-extract against all the .pgn files in the folder and save them to a (new) subfolder "clean". Options on the command-line before the folder will be passed along to pgn-extract, allowing you to keep or exclude anything that pgn-extract can keep or exclude. It's up to you to delete the originals and move the clean versions over. Beware, though -- Scid and pgn-extract handle a bad game within a pgn file differently. Don't expect cleaning with pgn-extract to give identical results to cleaning with Scid. Proceed with care, and verify your cleaned file(s) before deleting any original(s).
Caveat emptor: I tested this under Windows 10 using the latest 22.11 version of pgn-extract, but afterwards I made some cosmetic edits to the script before posting here (adding comments, removing my username, etc.). And I did those edits under Linux, without retesting. It
should work as-is, but no guarantees.
Edited: Updated pgn-clean.bat has been posted on 2023-08-29.