• Delete directory?
    1 replies, posted
So I'm trying to find a way to delete a directory, but using the File. commands all I can find is a file.CreateDir Is there not a CreateDir? Here's how far I've gotten with the simple virtual computer code: [code] basedir="fileshare" curdir="fileshare" curtab=file.Find(curdir.."/*") function sm(str,b) local pstr="" if b~=nil then local pstr="--"..str.."--" else pstr=str end print(pstr) end function getlastslash(str) local t=string.reverse(str) local tp=t:find("/") if tp==nil then return end local tpn=str:len()-tp return tpn+1 end function getdir() curtab=file.Find(curdir.."/*") end function updir() if curdir==basedir then sm("Denied",true) return end curdir=string.sub(curdir,1,getlastslash(curdir)-1) getdir() end function downdir(dir) curdir=curdir.."/"..dir getdir() end function listdir() getdir() PrintTable(curtab) end function readtxt(fi) local curfil=curdir.."/"..fi..".txt" if file.Exists(curfil) then sm(file.Read(curfil)) return file.Read(curfil) else sm("No File",true) return nil end end function writetxt(fi,str) local curfil=curdir.."/"..fi..".txt" //print(curfil) if file.Exists(curfil) then file.Write(curfil,file.Read(curfil)..str) elseif not file.Exists(curfil) then file.Write(curfil,str) end end function delefil(fi) local curfil=curdir.."/"..fi file.Delete(curfil) end function newdir(fi) local curfil=curdir.."/"..fi file.CreateDir(curfil) end function dircomms(player,command,args) //print(args[1],args[2]) if args[1]==nil then print("No Com",true) end if args[1]~=nil then if args[1]=="up" then updir() elseif args[1]=="dn" then downdir(args[2]) elseif args[1]=="list" then getdir() elseif args[1]=="writ" then writetxt(args[2],args[3]) elseif args[1]=="read" then readtxt(args[2]) elseif args[1]=="dele" then delefil(args[2]) elseif args[1]=="newd" then newdir(args[2]) end listdir() end sm(curdir) end concommand.Add("com",dircomms) [/code] As you can see, I have a delete command but this only works with .txt files. I apologise for my ultra messy lack of tabbing ;)
I don't think you can delete directories. There's nothing to do it in the file library and you can't delete directories using [B]file.Delete()[/B]. Also, a few hints: [B]1)[/B] If you want to check whether a variable exists, don't compare it to nil. The shorter way to do it is this: [lua] if ~variable then -- Check if variable is nil, you can also use the '!' character as an alternative to '~'. if variable then -- Check if variable exists [/lua] [B]2)[/B] It makes it easier for us if you use [noparse][lua][/lua][/noparse] tags. [B]3)[/B] Don't override libraries such as [I]player[/I], unless you have a reason to. Use something like [I]ply[/I] instead for your concommand.
Sorry, you need to Log In to post a reply to this thread.