Disk Manage v3.0 By Cheeky


ok, so this is my second program released on these forums. its the start of a disk manage. at the moment it will check for a drive, if a drive is found it will check for a disk. if a disk is found it will then ask for you to label it. then once it is lable'd it will be chucked out. note
that this was more of a test of my ability than actually make something useful. it took me a long time to code and im thinking of making it bigger. so it has a useful purpose. hopefully this will include a option to wipe the disk, one to clone the disk. i know its not useful at all, but can someone please check it out and tell me what they think? it may be something to include in a small os or something. thanks
version 2.0 is now released. it has all bugs and errors fixed and the code is much cleaner and easier to under stand. make sure you download 2.0
-Cheeky


[UPDATE]
NEW VERSION 3.0 YOU CAN NOW CLONE DISKS!!!!! EXTRA THANKS TO KAOS AND CRANIUM FOR HELPING ME CODE IT!!!!

–[Version List]–
v3.0 Clones a disk Only
v2.0 Relabels a disk only
v1.0 a crapper version of v2.0


Code:
Spoiler

fs.delete("disk2/")
fs.makeDir("disk2/")
sleep(3)
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 c = disk.isPresent(a)
	  local function copydisk2(path)
  local path=path or ''
  for k,x in pairs(fs.list('disk2'..'/'..path)) do
		if fs.isDir(x) then
		  copydisk(path..'/'..v)
		elseif fs.exists('disk2/'..path) then
		  fs.copy('disk2/'..path..'/'..x,'disk/'..path..'/'..x)
		end
  end
end
	  local function copydisk(path)
  local path=path or ''
  for k,v in pairs(fs.list('disk'..'/'..path)) do
		if fs.isDir(v) then
		  copydisk(path..'/'..v)
		elseif fs.exists('disk/'..path) then
		  if not fs.exists('disk2/'..path) then fs.makeDir('disk2/'..path) end
		  fs.copy('disk/'..path..'/'..v,'disk2/'..path..'/'..v)
		end
  end
end
		   local function dcopy()
			 print("Scanning Disk...")
			 sleep(1)
			 print("Copying Disk...")
copydisk()
			 print("Disk Copied.")
			 disk.eject(a)
			 sleep(1)
print("Please Enter New Disk")
while true do
	  local j = disk.isPresent(a)
  sleep(3)
  if j then
print("New Disk Found")
sleep(1)
print("Pasting Disk...")
	 sleep(1)
copydisk2()
sleep(1)
print("Disk Pasted")
disk.eject(a)
	 sleep(2)
	 fs.delete("disk")
	 fs.delete("disk2")
	 break
end
end
			end

	   if b then
		 sleep(1)
		 print("Drive Found")
		 print("Checking for Disk...")
		   if c then
			 sleep(1)
			 print("Disk Found")
			 dcopy()
		   else
			 sleep(1)
			 print("No Disk Found")
		   end
	   else
		 sleep(1)
		 print("No Drive Found")
	   end
else
   print("Invalid Drive Side")
end



version 2.0
Spoiler

	
write("Please Enter Drive Side: ") -- asks to input the drive side
local a = io.read() -- takes ented side into a local varible. the varible is a
  if a == "top" or a == "bottom" or a == "left" or a == "right" or a == "front" or a == "back" then -- checks to see if it is a valid side
	print("Checking for drive...")  
	 local b = peripheral.isPresent(a) -- checks if drive is on the input side returns true if it is false if it is not. takes it into local varible b
	 local c = disk.isPresent(a) --checks if disk is in the drive -- returns true if it is false if its not. takes it into local variable c
		   local function drn() -- local function that labels the disk
			 write("Please Enter Disk Name: ")  -- asks for a disk label
			 local d = io.read() -- takes the input text into a local variable d
			 print("Setting Label...")
			 sleep(1)
			 disk.setLabel(a, d) -- sets the label on the inputted side with the input text
			 print("Label Set")
			 disk.eject(a) -- ejects a disk out of the input side
			end
			
	   if b then -- checks for if varible b returned true
		 sleep(1)
		 print("Drive Found")
		 print("Checking for Disk...")
		   if c then -- checks for varible c returns true
			 sleep(1)
			 print("Disk Found")
			 drn()
		   else
			 sleep(1)
			 print("No Disk Found")
		   end
	   else
		 sleep(1)
		 print("No Drive Found")
	   end
else
   print("Invalid Drive Side")
end
	







Version 1.0
Spoiler

term.clear()
term.setCursorPos(1,1)
write("Enter Drive Side: ")
a = io.read()
	local dip = disk.isPresent(a)
	local function dcheck()
print("Checking For disk...")
sleep(1.5)
if dip == true then
print("Disk Detected!")
write("Enter Disk Label: ")
c = io.read()
print("Writing Label To Disk...")
sleep(1.5)
disk.setLabel(a, c)
print("Disk Label Set!")
disk.eject(a)
elseif dip == false then
sleep(1.5)
print("No Disk Detected!")
end
end
  if a == "top" or a == "bottom" or a == "front" or a == "back" or a == "left" or a == "right" then
	local drp = peripheral.isPresent(a)

	print("Checking For Drive...")
	sleep(1.5)
if drp == true then
  print("Drive Found!")
dcheck()
else
print("No Drive Detected!")
end
end

This should work. if it doesn't then PLEASE TELL ME AT ONCE ^_^/>/>
thanks again -Cheeky