Jump to content




fs api, need help on a new topic


  • You cannot reply to this topic
9 replies to this topic

#1 cheekycharlie101

  • Members
  • 231 posts

Posted 31 October 2012 - 12:55 PM

ok, so thanks to all the awesome people here my disk manager is now almost complete. i can clone a disk, re label a disk and now i just need to be able to wipe a disk.
ok so the only way i can think of doing this is putting fs.list() into a variable then delete the variable. this probably wont work as i have not tested it yet but would this be any good? if not can someone help me out please ?:P/>

here is what i thought up:

local a = fs.list("disk/"!)
sleep(1)
print("Wiping DIsk...")
fs.delete(a)
print("Disk Cleared")
if this does not work can someone help me out and give me a few pointers?
thanks -Cheeky

#2 1lann

  • Members
  • 516 posts
  • LocationSeattle

Posted 31 October 2012 - 01:51 PM

Sadly computers cannot read our minds and tell exactly what we want it to do, so you have to be ultra specific and take note of what each function actually "does". Fs.list returns a "table" of the files and folders in "string" form in a specified directory. Fs.delete deletes a file and accept only "string" as arguments. What you're doing is like trying to stick money notes into a coin slot. It won't work. So what you need to do is go through every entry of the table and fs.delete the entry. (Not deleting the entry, deleting the file the entry is referring to). We can do this by using a for statement. The code would look something like this

for k, v in pairs(fs.list("disk")) do fs.delete(v) end

The variable k represents the index of the table you're at, the variable v represents the value of that index.

#3 cheekycharlie101

  • Members
  • 231 posts

Posted 31 October 2012 - 08:31 PM

thanks, iv'e seen that for loop example in pairs a lot before but dont really under stand it. could you explain further? that would be great.
thanks -Cheeky

#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 31 October 2012 - 08:40 PM

Maybe this will be a good example :?

They loop through a table
tbl = { apples = 2, oranges = 3 }
for k, v in pairs(tbl) do    -- k = "Key", v = "Variable"
  print(k, v) -- K will print "apples, oranges" V will print the numbers - 2, 3
end


#5 cheekycharlie101

  • Members
  • 231 posts

Posted 31 October 2012 - 11:41 PM

er ignore this, i fucked up and could not delete it read post below


|
|
|
|
|
|
|

#6 cheekycharlie101

  • Members
  • 231 posts

Posted 31 October 2012 - 11:45 PM

View Post1lann, on 31 October 2012 - 01:51 PM, said:

Sadly computers cannot read our minds and tell exactly what we want it to do, so you have to be ultra specific and take note of what each function actually "does". Fs.list returns a "table" of the files and folders in "string" form in a specified directory. Fs.delete deletes a file and accept only "string" as arguments. What you're doing is like trying to stick money notes into a coin slot. It won't work. So what you need to do is go through every entry of the table and fs.delete the entry. (Not deleting the entry, deleting the file the entry is referring to). We can do this by using a for statement. The code would look something like this for k, v in pairs(fs.list("disk")) do fs.delete(v) end The variable k represents the index of the table you're at, the variable v represents the value of that index.
ok so i got this code, it works perfectly, accept it dont wipe the disk. there is no errors or anything. here is the code. il then go through the steps underneath so you know what the code is surposed to do:

here is the code:
write("Please Enter Drive Side: ")
local a = io.read()
  if a == "top" or a == "bottom" or a == "left" or a == "right" or a == "front" or a == "back" then
    print("Checking for drive...")
	 local b = peripheral.isPresent(a)
	   local function dclean()
		 print("Please Enter Disk")
		  while true do
		    local c = disk.isPresent(a)
			 sleep(1)
			 if c then
			   print("Disk Found")
			   sleep(1)
			   print("Wiping The Disk...")
			   sleep(1)
			   for k,v in pairs(fs.list("disk/")) do
			   fs.delete(v)
			   print("Disk Wiped")
			   disk.eject(a)
			  sleep(1)
			   break
			 end
		   end
		 end
	   end
			   
	 if b then
	   sleep(1)
	   print("Drive Found")
	   dclean()
	 else
	   sleep(1)
	   print("No Drive Found")
	 end
   else
	 sleep(1)
	 print("Invalid Drive Side")
   end

1. input the drive side -- if no drive side is found then it prints that and ends the program. it does the same for a invalid side
2. it asks for a disk, if the disk is found it then prints wiping disk then ejects it. it ejects it but does not wipe it.

#7 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 01 November 2012 - 12:18 AM

I think fs.list only returns filenames, and not paths.

In this part of the code:
for k,v in pairs(fs.list("disk/")) do
fs.delete(v)

You would do
for k,v in pairs(fs.list("disk/")) do
fs.delete("disk/"..v)
end

I added the end there because I think you're missing it, but i might be wrong. If the program breaks for whatever reason, remove the end.

#8 cheekycharlie101

  • Members
  • 231 posts

Posted 01 November 2012 - 12:47 AM

View PostKingdaro, on 01 November 2012 - 12:18 AM, said:

I think fs.list only returns filenames, and not paths.

In this part of the code:
for k,v in pairs(fs.list("disk/")) do
fs.delete(v)

You would do
for k,v in pairs(fs.list("disk/")) do
fs.delete("disk/"..v)
end

I added the end there because I think you're missing it, but i might be wrong. If the program breaks for whatever reason, remove the end.
thanks, il go test this now

#9 cheekycharlie101

  • Members
  • 231 posts

Posted 01 November 2012 - 12:50 AM

View PostKingdaro, on 01 November 2012 - 12:18 AM, said:

I think fs.list only returns filenames, and not paths.

In this part of the code:
for k,v in pairs(fs.list("disk/")) do
fs.delete(v)

You would do
for k,v in pairs(fs.list("disk/")) do
fs.delete("disk/"..v)
end

I added the end there because I think you're missing it, but i might be wrong. If the program breaks for whatever reason, remove the end.
thanks sooooo much bro :P/> it worked :DDDD thanks so much :P/>

#10 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 01 November 2012 - 01:21 AM

Check this out :P/>

Spoiler






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users