Good morning, I have a problem, use this code, but even without the usb it appears that it is connected. My question is how do I place the USB location?
I'm working it this way...
path = 'mnt/PalominoSyT'
if io.exists(path) then
os.execute('mount' .. path .. ' /mnt')
alert('USB mont')
else
alert('USB not found')
end
path = '/mnt'
status = io.exists(path)
io.writefile(path .. 'new.txt', 'This is a test')
result = io.readfile(path .. 'new.txt')
lea = io.readfile('TestLMUsb.txt')
Use this function to mount USB properly, in alerts you will get either ok or an error message. By default it mounts the first partition from USB drive to /mnt so you don't have to change anything unless you don't want it to work
Code:
function mountusb(part, mnt)
part = part or '/dev/sda1'
mnt = mnt or '/mnt'
local cmd = string.format('mount %q %q 2>&1', part, mnt)
local res, stat = io.readproc(cmd)
return stat == 0 and true or nil, res
end
res, err = mountusb()
if res then
alert('USB OK')
else
alert('USB error: ' .. tostring(err))
end
Then, to read/write files you need to supply full path like /mnt/myfile.txt. Because in your case path .. 'new.txt' becomes /mntnew.txt which will be written to the main file system instead of USB drive.
Go to system config -> status -> system log. When you connect your USB drive it will show the list of partitions. Some incorrectly formatted drives might use the whole drive without partitions, then you should try mountusb('/dev/sda')
I already changed it, but I still get the error, when I put mountusb ('/ mnt') the status is USB ok but it is not taking the USB.
With this code I also get error, I do not know what else to try.
<code>
function mountusb(part, mnt)
part = part or '/dev/sda1'
mnt = mnt or '/mnt'
local cmd = string.format('mount %q %q 2>&1', part, mnt)
local res, stat = io.readproc(cmd)
return stat == 0 and true or nil, res
end
res, err = mountusb('/dev/sda')
if res then
alert('USB OK')
else
alert('USB error: ' .. tostring(err))
end
</code>