599 posts
Location
LeLua
Posted 27 July 2015 - 11:44 AM
For example my file is in the: /Dada/Yup/FileContent/main.lua
And i want to find my file always, cuz this file will be changing locations :)/>
Thanks in advance.
656 posts
Posted 27 July 2015 - 12:24 PM
shell.getRunningProgram ()
for the file path, and
fs.getDir (shell.getRunningProgram ())
for the directory.
223 posts
Location
Minecraft in Minecraft in Minecraft in ComputerCraft... in Minecraft
Posted 27 July 2015 - 12:26 PM
I think
fs.find is your answer.
(This code should work)
local file = textutils.serialize( fs.find( "main.lua" ) )
if #file == 0 then
error( "Cannot find file...", 0 )
elseif #file == 1 then
print( "main.lua is located at: " .. file[ 1 ] )
elseif #file > 1 then
print( "main.lua is at multiple locations." )
print( "It could be at " .. file[ 1 ] )
for i = 2, #file do
print( "Or at " .. file[ i ] )
end
end
1140 posts
Location
Kaunas, Lithuania
Posted 27 July 2015 - 12:48 PM
I think
fs.find is your answer.
(This code should work)
local file = textutils.serialize( fs.find( "main.lua" ) )
if #file == 0 then
error( "Cannot find file...", 0 )
elseif #file == 1 then
print( "main.lua is located at: " .. file[ 1 ] )
elseif #file > 1 then
print( "main.lua is at multiple locations." )
print( "It could be at " .. file[ 1 ] )
for i = 2, #file do
print( "Or at " .. file[ i ] )
end
end
fs.find doesn't look for a file in the whole filesystem. It simply allows to find files based on a given path. A part of the path can be a wildcard.
599 posts
Location
LeLua
Posted 27 July 2015 - 08:32 PM
Thanks guys, ill test it tomorow.