In general, it is a good idea to install your carpet before you hang your internal doors. This applies to bifold doors as well. If you choose to hang your doors first, you will have to take them down again in order to make sure the carpet is fitted correctly and you find you need to plane some off the bottom of the door to avoid contact with the carpet. So, while it is possible to do the door first, it is something of a waste of time as removing and rehanging doors is not necessarily any easier than installing them after.