22.03.2017, 06:55
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
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.
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.