Yes, this is possible.
You need a third-party launcher that can handle multiple instances of Minecraft seperately. One example is the open source project https://github.com/PrismLauncher/PrismLauncher which I will use for explaining.
How it works is that each created instance has its own .minecraft folder, you log in with your Microsoft account like the Vanilla launcher and it fetches the required files automatically.
Once an instance is created, for which in your case you would need to create a 1.19 instance and a 1.12 instance, you can explore the instance files using the folders dropdown.
You can then freely explore both instances seperately, change settings seperately and install mods seperately in their respective mods folders.
As you can see, my Fabric 1.19.2 instance has its own .minecraft folder.
Any launcher that offers multiple instancing will work, but always use caution when downloading files from the Internet. Third-Party launchers are not endorsed by Mojang.