Yesterday evening I ran into a stupid problem: in CodeCaddy the codesync function no longer worked. Well, it worked sort of, but never created any folders. That was weird... that was one thing I had not changed, so I started digging in my code.
makesuredirectorypathexists_()
shcreatedirectoryex_()
Turned out I was using a WinApi call (MakeSureDirectoryPathExist) to create the folders, and sure enough, that one only existed in an Ascii flavour, but not for Unicode. Hmm. There was an alternative (SHCreateDirectoryEx) but alas, for that one I had to open a library / DLL, and it did not exist on all platforms.
Dang. So get on your coding wagon cowboy and start hammering.
x_getdeepestpath(s.s)
x_getparentpath(s.s)
x_absolutepath(s.s)
x_createdirectory(folder.s)
These four routines allow a little manupulation of file paths. x_getdeepestpath() and x_getparentpath() are complementary... The first one turns 'c:\windows\system32\' into 'system32\', and the latter returns 'c:\windos\system32\'.
x_absolutepath() takes a path, including relative paths using '..\' or '\' and tries to find, based on the current directory, the associated absolute path. Obviously I'm a lazy basterd, so I used x_getparentpath() whenever I encountered a '..\' combo.
But... I needed to create a folder structure to replace my WinApi call. So I took a path, turned it into an absolute path, then started parsing through it. Whenever I hit an existing folder in the chain I would not have to create a subfolder, just continue. So if I had the following folder structure:
c:\
c:\windows\
c:\windows\system32\
... I would pare it like: c:\ -> c:\windows\ -> c:\windows\system32\ -> then I should be able to create a subfolder under system32 like this: x_createdirectory("c:\windows\system32\whatever")
It worked. Until I actually tried my new routine inside CodeCaddy. And no folders were created. It turned out I had three small and unrelated different bugs in all three routines, and they confused the hell out of me. I hope I have them fixed now, so much time spend on less than a 100 lines... just because I returned an empty string as the parent folder of 'c:\'...
(By the way: how do you test the integrity of your includes / libraries? I use a seperate file called x_lib_test.pb, and every time I add a new function, or find a new bug, I add checks to that file, hoping that this will alert me in case I break something else... Unit testing for beginners, I guess

)