Friday, March 30, 2012

Tales of Woe of a Windows user

This woman is trying to empty a Windows folder. God help her.
I've not updated this blog in a long time, but today I'd like to share a painful experience. First, I'm an Opera user, and while I'm overall quite happy with the browser, it won't empty its disk cache on exit, even though it is supposed to. As a result, the cache tends to exceed 10GB after a while. When I first noticed this, I figured "OK, that's annoying but no big deal, I'll just create a shortcut to the cache directory on my desktop and manually empty it from time to time."

So I created the shortcut, but things didn't exactly go as planned. Opera breaks down its cache into many small .tmp files, so the cache directory often contains many thousands of tiny files. Now, as any Windows user is aware, simply deleting a file will actually send it to the recycle bin, but pressing shift at the same time will delete it for good. For some obscure reason that still eludes me, it is impossible to fully delete more than about 1200 files at once without going through the recycle bin, or at least my system refuses to do so and sends everything to the bin. I'm not sure whether Windows modifies the files in any way when sending them to the bin, but because they are so numerous in the disk cache, the deletion process takes forever. As if that weren't enough, it also slows the entire system down, and I still have to empty the bin afterwards to actually delete the files.

Needless to say, I quickly decided that this just wasn't an acceptable way of doing this, and I had to find something better. On most distributions of Linux, I just would have right-clicked in the folder, clicked Open terminal here or some similar option, typed rm * and pressed Enter, for a grand total of 2 clicks and 5 keys pressed. So I figured that doing something similar on Windows ought to be possible. It turns out that directly opening a PowerShell in a specific directory is impossible, so I had to open it at the root of my system, and then go to the desired directory. That sounds trivial, but PowerShell's auto-completion system is so terrible that it's actually quite a pain in the ass. Anyway, I finally reached the cache directory, typed Remove-Item *, pressed Enter, and finally my cache emptied itself correctly, without going through the bin, and taking a reasonable amount of time.

But this still wasn't good enough. Opening a shell and going to the right directory was far too tedious to do manually every time, so I decided to just write a script to do it. So I did, and I put it on my desktop. Then, I double-clicked it… which launched Notepad, with the script in it. OK, fine, Linux would have asked me whether I wanted to run it or display it, but that's not too bad. I closed it, right-clicked it, and clicked Run with Powershell. Then, a nice little command-line window opened, displayed some red text for a fraction of a second, and closed before I could read a single word. WTF? I tried it again, and managed to take a screenshot just in time. As it turned out (after a good bit of googling around) it's not possible to run your own scripts on Windows with the default settings. You have to launch PowerShell, and type in Set-ExecutionPolicy RemoteSigned, otherwise the OS refuses to run your scripts, because it doesn't trust them. So I did just that, and now I can run my little script from my desktop to empty my disk cache, with minimal human input and just a few seconds of work for the system.

Sure, originally, this is a bug on Opera's side, so in a way, this is Opera Software's fault more than Microsoft's. But the point of this blog entry is that because Windows is so weird, and in some ways so far behind Linux (on which it would have been the most trivial thing in the world) it took me 20 minutes to figure out how to empty a fucking folder.