224 posts
Location
Auckland, New Zealand
Posted 07 February 2013 - 07:45 PM
How do you get your current dir?
What I'm trying to use is this:
cDir = shell.dir()
fs.makeDir(cDir,"sel")
-- What it should do is get the current directory and then use it in the fs.makeDir
--But it returns an error:
--Line 2 - Expected String
Thanks, AnthonyD98
7508 posts
Location
Australia
Posted 07 February 2013 - 07:48 PM
fs.makeDir(cDir,"sel")
should be
fs.makeDir(cDir.."sel")
EDIT: However there is a problem when using shell.dir() in certain cases.
if you wish to get the directory of the current running program then it wont always work. For example
CraftOS
> someProgram <-- run the program
<-- base path "/"
> cd somePath <-- change the active directory
somePath> /someProgram <-- run it from this directory
somePath <-- note that its not the programs dir, but the one we are in
somePath>
so how do we fix this? easy
local function getRunningPath()
local runningProgram = shell.getRunningProgram()
local programName = fs.getName(runningProgram)
return runningProgram:sub( 1, #runningProgram - #programName )
end
this gets the running program, which is the full path
somePath/someProgram
then it gets the programs name
someProgram
and returns the substring from the full path starting at index 1 and ending at the full path's end minus the length of the programs name
Edited on 07 February 2013 - 06:56 PM
224 posts
Location
Auckland, New Zealand
Posted 07 February 2013 - 07:50 PM
fs.makeDir(cDir,"sel")
should be
fs.makeDir(cDir.."sel")
EDIT: However
That worked but I also had to add a / before the sel
Thanks for your help :)/>
EDIT: Just saw your edit
Edited on 07 February 2013 - 06:51 PM
224 posts
Location
Auckland, New Zealand
Posted 07 February 2013 - 07:56 PM
So If I wanted my program to automatically detect what dir it was running in and to apply those changes to the fs functions it does.
so fs.makeDir(".config")
becomes fs.makeDir(cDir.."/.config")
What if I was in root
would the / cause an error?
EDIT: Viewing your edit now . . .
Edited on 07 February 2013 - 06:57 PM
7508 posts
Location
Australia
Posted 07 February 2013 - 07:57 PM
So If I wanted my program to automatically detect what dir it was running in and to apply those changes to the fs functions it does.
so fs.makeDir(".config")
becomes fs.makeDir(cDir.."/.config")
What if I was in root
would the / cause an error?
see the finished edit ;)/>