macos – Delete all macbook data and keep a certain folder?

I can not find a clear step-by-step guide – how completely delete all the data + applications + cache of my mac (to give it to another friend), but keep a certain folder I can not do a backup otherwise (it's 40 GB and we're far from home).

Therefore, macbook pro with MacOS Mojave , I have 1 folder on the desktop and I want to delete all the mac data, including all the applications and the cache, and leave this folder there.

We can and must keep the Mojave OS as I just downloaded it.

I mean really remove everything since it has a lot of garbage, cache and private keys, etc.