Using the full path, the one returned from getExecutionPath(), should be fine to use with mkdir.
Code: Select all
os.execute("mkdir " .. string.gsub(getExecutionPath(), "/+", "\\") .. "\\userdir");
string.gsub is used to convert the standard POSIX-style directory slashes to Windows-specific backslashes. I was quite certain that I had the fixSlashes() function available to do this in MicroMacro, but apparently I never exported it, and it is a local function in the lib. Guess I'll move that for the future.
Alternatively, you could find the last instance of '/' in the path then return the substring starting after that location to get the directory name. The problem with this is that nested directories would break it.
Unless I'm mistaken, isn't there some global variable that holds the base path? I'm pretty sure at one time there was something that held the execution path at start-up so we could tell which directory the bot files were in.
Also, there is a function,
isDirectory(), that will check if a directory exists. I would recommend using that instead of checking it as a file because, obviously, that would allow a file to be considered a directory.
should work and would have made it easier but it's not working. I suspect it's interpreting the slash as the beginning of a special character.
Most likely, it is because that example had single backslashes, which is the escape character. Double backslashes would be needed.
Ah, when I tried double slashes I thought it didn't work because it created it in the root directory. I forgot starting a path with slash is supposed to do that.
Kind of. I wouldn't rely on that behavior. Not that we're really focusing on running MicroMacro under a UNIX OS (it just doesn't work; I'd like to have that, but how MicroMacro uses Windows' internals just doesn't work out so well on a more secure OS), but beginning with a slash could end up being disastrous, as it essentially would be the same as putting "C:/" in there. "./" or ".\\" would be most appropriate for relative pathing.
Or maybe Administrator would like to add them as basic functions to micromacro? Or maybe she could add a file system library to MM?
Undecided. I was considering adding PhysicsFS to MicroMacro. Would be nice, but I still can't see too much use for it. Could make updating via distributing zip files much easier (just tell the user to drop the zip file in the directory, and that's it. It would take care of everything else). As for simple FS functions like creating directories, I guess I just never bothered since it could already be done with os.execute().