Typically the treatment for onychomycosis can take from months to years to never, so there is not right answer that can be given as to “how long?”.
The reason for the uncertainty is due to a number of reasons. The onychomycosis is caused by a fungal infection that gets into the nail plate. Whatever treatment that is used can not actually get rid of it. What the treatments do is “kill it” or stop it spreading, so that means you have to wait for the nail to grow out, which can take several months and some treatment is still needed that time to stop it spreading and to prevent re-infection.
The other problem is that the fungus that causes the onychomycosis likes darkness and moisture. That is the exact environment that you get inside the shoes. This means that you are trying to treat an infection that is in the environment it likes, so this makes it harder to treat and re-infection is common which will further extend the time it can take to get rid of it.
An additional problem is that if the infection is anything other than superficial, there is a chance that it has got into the cells that the nail grows from and damaged them, so that in the long term the nail plate is distorted. Because of that damage to the growing cells, this could be a long term issue.
If the onychomycosis infection is a simple and superficial one, then it can easily be got rid of in a month or so. If the infection is deep inside the nail and the nail plate is distorted or damaged, this can go on for year and maybe never get fixed. In either case, it is relatively easy for a re-infection to occur and make it an ongoing problem.