Advertisement
Leka74

Snippet: DeleteAllExcept

Feb 17th, 2011
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. --[[ What's the easiest way to delete all the files with AMS except one? Here is a simple snippet to do the job:]]
  2.  
  3. -- The function
  4. function File.DeleteAllExcept(strPath, strFile)
  5.     tblFiles = File.Find(strPath, "*.*", false, true, nil, nil);
  6.     for i,e in pairs(tblFiles) do
  7.         strPath = String.SplitPath(tblFiles[i]);
  8.         strFilename = strPath.Filename..strPath.Extension;
  9.         if strFilename ~= strFile then
  10.             File.Delete(tblFiles[i], false, false, false, nil);
  11.         end
  12.     end
  13. end
  14.  
  15. -- Example:
  16. File.DeleteAllExcept(_DesktopFolder.."\\Personal Pictures\\", "rainyday.jpg")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement