Announcement

Collapse
No announcement yet.

Folder.SmartDelete

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Folder.SmartDelete

    Hello,

    I'm trying to create a function that deletes folders in a smarter way. The normal Folder.Delete does not delete a folder when there are other files and folders in it. Currently i am solving the part of deleting folders. This is what my code looks like.

    Code:
    function Folder.SmartDelete(f)
    	if f then
    		if Folder.DoesExist(f) == true then
    			local folders = Folder.Find(f, "*", true, nil)
    			if folders then
    				local i = ""
    				local v = ""
    				
    				for i, v in pairs(folders) do
    					Folder.SmartDelete(v)
    				end
    			else
    				Folder.Delete(f)
    			end
    		end
    	end
    end
    But it isn't working perfectly. Try it yourself. When you have multiple top level folders with some child folders it doesn't delete the last top level folder. It may be other kind of program code that causes it but i am not sure. I would appreciate it if you can help me fix this thing. And maybe in a way it deletes files in those folders too.
    So that other AMS users can have this function too.

    I am pretty sure i did see something similar on this forum...but can't find it.

  • #2
    What's wrong with Folder.DeleteTree?

    Comment


    • #3
      Hahahahahaha sorry. Oh my, i didn't see that function 0_o. Guess i'm tired. It wasn't in previous versions of AMS right?

      Anyways, soon i still need the function as i described. But in a way i can supply an array of files / folders to be ignored. Kinda like a blacklist. That blacklist functionality i can create myself. But it would be nice to see if someone can Build Folder.DeleteTree like i've tryed

      Thanks!

      Comment


      • #4
        In your example you clear "i" and "v" before your for loop. In Lua, this isn't necessary as any variables declared in the for loop are localised and their scope does not extend outside the loop.

        So your:
        Code:
        local i = ""
        local v = ""
        variables are not the same variables as the "i" and "v" declared in your loop.

        Comment

        Working...
        X