fs.move Not working?
#1
Posted 03 July 2013 - 01:20 PM
rnd = tostring(math.random(101, 999))
then it prints a message with that number as a reference code... then I do this:
fs.move ("users/".. userlog, "pending/".. rnd)
It makes the new file just fine, however it does not delete the old one from the users folder. Any ideas why? The error I got is this:
login:142: Access denied
line 142 is where the fs.move is so I KNOW its a problem with that but can't see where I went wrong...
#2
Posted 03 July 2013 - 01:22 PM
When you use anyname = fs.open("filename","handle"), when you are done using anyname, do anyname.close().
#3
Posted 03 July 2013 - 01:24 PM
#4
Posted 03 July 2013 - 01:31 PM
rnd = tostring(math.random(101,999))
file = fs.open("users/".. userlog, "r")
file.move ("users/".. userlog, "pending/".. rnd)
file.close()
is that close at least? :-p
EDIT: I must be close cause now I get login:143: attempt to call nil
143 is the file.move line...
#5
Posted 03 July 2013 - 01:43 PM
#6
Posted 03 July 2013 - 02:05 PM
file = fs.open("users/"..userlog, "r")
file.close()
fs.move ("users/".. userlog, "pending/".. rnd)
Thing is at the moment of moving it shouldnt be reading the file at all... it reads it when it checks the password but then closes... here I will give you a larger snippet...
ulog = fs.exists("users/".. userlog)
if ulog == true then
ulog = fs.exists("users/".. userlog)
if (ulog and ulog:read()==userpas) then
term.setCursorPos(16, 18)
print(" Login Success...")
sleep(3)
else
if lockdown < 2 then
term.setCursorPos(16, 18)
print(" Wrong Password ")
sleep(3)
if userlog == puselog then
lockdown = lockdown+1
else
lockdown = 0
puselog = userlog
lockdown = lockdown+1
end
else
term.setCursorPos(15, 18)
rnd = tostring(math.random(101,999))
print(" Lockdown Ref #: ".. rnd)
sleep(3)
file = fs.open("users/".. userlog)
file.close()
fs.move ("users/".. userlog, "pending/".. rnd)
end
end
else
(Code goes on to a different branch of operations for handling an unknown username from here)
#7
Posted 03 July 2013 - 05:23 PM
#8
Posted 03 July 2013 - 07:50 PM
#9
Posted 03 July 2013 - 07:59 PM
edit: and as far as I can tell... the file isnt opened any other time... unless doing a fs.exists opens it?
#10
Posted 03 July 2013 - 08:21 PM
#11
Posted 03 July 2013 - 08:26 PM
../users/Boudragon
../pending/###
The idea is that when they fail to use the correct password 3 times it generates a random number... displays the number as a reference code and then moves the Boudragon file to the pending directory while also renaming it to the random number.
EDIT: In case you are wondering... YES I added a check to make sure the random number isnt already taken by another file. So the code above is a little out dated so-to-speak but either way... should work the very first time AT LEAST... lol
#12
Posted 03 July 2013 - 08:27 PM
#13
Posted 03 July 2013 - 08:30 PM
Also I KNOW my directories work just fine... I am able to create accounts, login successfully... everything else works BUT THIS... the lockout feature...
#14
Posted 03 July 2013 - 09:38 PM
#15
Posted 03 July 2013 - 09:42 PM
#16
Posted 04 July 2013 - 01:27 AM
#17
Posted 04 July 2013 - 04:36 AM
Quote
You call a function here, could you paste a snippet with this function please. I am assuming that you open a file and read from it here... (this could be why you can not delete the file hence the Access Denied)
Also try adding "./users/" ..
and "./pending/" ..
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh... I see the error now while typing this.
/" gives you a string with a " in it instead of a /
try
fs.move ("users//".. userlog, "pending//".. rnd)
could be something silly like that. the interpreter could be taking "users/".. userlog, " as a single string instead of taking users/ then appending userlog
...
#18
Posted 04 July 2013 - 08:50 AM
#19
Posted 04 July 2013 - 09:56 AM
local pass
ulog = fs.exists("users/".. userlog,"r")
if ulog == true then
ulog = io.open("users/".. userlog)
pass=ulog and ulog:read()
ulog:close()
if (pass and pass==userpass) then
term.setCursorPos(16, 18)
print(" Login Success...")
sleep(3)
else
if lockdown < 2 then
term.setCursorPos(16, 18)
print(" Wrong Password ")
sleep(3)
if userlog == puselog then
lockdown = lockdown+1
else
lockdown = 0
puselog = userlog
lockdown = lockdown+1
end
else
term.setCursorPos(15, 18)
rnd = tostring(math.random(101,999))
print(" Lockdown Ref #: ".. rnd)
sleep(3)
--# I never said you had to open it to move it, I said every time you are done with a file handle, close it!
fs.move ("users/".. userlog, "pending/".. rnd)
end
end
else
I fixed the code you gave me, if it still doesnt work its because some other part is broken.Edit:
albrat, on 04 July 2013 - 04:36 AM, said:
Quote
You call a function here, could you paste a snippet with this function please. I am assuming that you open a file and read from it here... (this could be why you can not delete the file hence the Access Denied)
Also try adding "./users/" ..
and "./pending/" ..
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh... I see the error now while typing this.
/" gives you a string with a " in it instead of a /
try
fs.move ("users//".. userlog, "pending//".. rnd)
could be something silly like that. the interpreter could be taking "users/".. userlog, " as a single string instead of taking users/ then appending userlog
...
You are mixing forward slashes, /, with backward slashes, \. Backward slashes are the escape characters.
#20
Posted 04 July 2013 - 10:17 AM
EDIT: At this point I'm willing to face scrutiny for my messy programming and pastebin the unfinished code just to get the darn thing working LMAO! Would that help? :-p
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











