Is there a way to delete a folder in Windows and not having the time taken proportional to the number of files within it?
Well, yes, format the partition. I'm a bit surprised nobody suggested that in the previous 9 years.
It's pretty radical, but if you anticipate doing this frequently for a specific folder, it might be worthwhile creating a separate partition for it.
If that's too radical, the other answers are your only hope. There is a good explanation why on serverfault. It's for linux and XFS filesystems, but the same logic applies here. You can't improve much on build-in OS functions.
However, if you know the paths to all the files you wish to delete, then you can save on calls that list the directory contents and call remove directly, saving some overhead. Still proportional to the number of files though.
Personally, I like some from of progress report to ensure myself that the program didn't die. So I like to delete stuff via python. For example, if all the files are in one directory without sub-directories:
location = sys.argv
directory = os.fsencode(location)
with os.scandir(directory) as it:
for dir_entry in tqdm.tqdm(it):
pass # was not a file
This deletes about 250 files/s on my 12 year old SEAGATE ST3250620NS. I'd assume it will be much faster on your drive.
However, at this point it's just micro-optimization, so won't do very much unless you have millions of files in one directory. (like me, lol, what have I done D:)