Script to delete current playing file in Windows
Posted: 22 Sep 2013 20:59
This is a quick and dirty script I wrote which will mark the currently playing file for deletion in Windows.
Windows cannot delete the current playing file so long as it is currently playing since the file is open/locked and cannot be deleted because Window's sucks(that's my technical explanation). To get around this the path/filename is written to a temp file and the next time the script is activated the previously marked file will be physically removed.
Windows cannot delete the current playing file so long as it is currently playing since the file is open/locked and cannot be deleted because Window's sucks(that's my technical explanation). To get around this the path/filename is written to a temp file and the next time the script is activated the previously marked file will be physically removed.
Code: Select all
function descriptor()
return { title = "DeleteFile for VLC" ;
version = "0.003" ;
author = "Trevor Sturdevant";
shortdesc = "Physically delete a file from disk";
description = "DeleteFile - Physically deletes/removed the current playing file"
.. "from disk [eventually]. No confirmation is asked. If you do not want to"
.. "delete the file do not click the extension. The file is not actually deleted"
.. "until the next time the extension is activated. This is provided for"
.. "academic purposes only. This cannot be sold or reproduced for any profit."
.. "No warranties are expressed or implied by making use of this code."
.. "Use at your own risk."
.. "Place this into %APPDATA%\vlc\lua\extensions\delefile.lua"
.. "It could be coded better but I just wanted to get it done for personal use"
.. "but have decided that sharing is caring.";
url = "http://none.sorry/"
}
end
function activate()
vlc.msg.dbg("DeleteFile: activated")
local tempf = string.gsub(os.getenv("TEMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat"
local f,err = io.open(tempf, 'r')
if err then
local tempf = string.gsub(os.getenv("TMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat"
local f,err = io.open(tempf, 'r')
if err then
local tempf = string.gsub(os.getenv("USERPROFILE"),"\\","/") .. "/vlc_DeleteFile_tmp.bat"
local f,err = io.open(tempf, 'r')
end
end
if f~=nil then
f:close()
local tempwinf = string.gsub(tempf,"/","\\")
local delCmd = "start /min /wait cmd /E:ON /c " .. tempwinf
os.execute(delCmd)
os.remove(tempf)
end
delete()
deactivate()
end
function deactivate()
vlc.msg.dbg("DeleteFile: deactivated")
vlc.deactivate()
end
function close()
vlc.msg.dbg("DeleteFile: closing")
deactivate()
end
function playnext()
vlc.playlist.next()
end
function delete()
local item = vlc.input.item()
local uri = item:uri()
local filename = vlc.strings.decode_uri(uri)
filename = string.sub(filename,9)
local dosfilename = string.gsub(filename,"/","\\");
vlc.msg.dbg("DeleteFile: received \"" .. filename .. "\"")
vlc.msg.dbg("DeleteFile: dos fname \"" .. dosfilename .. "\"")
local tempf = string.gsub(os.getenv("TEMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat"
local f,err = io.open(tempf, 'a')
if err then
local tempf = string.gsub(os.getenv("TMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat"
local f,err = io.open(tempf, 'a')
if err then
local tempf = string.gsub(os.getenv("USERPROFILE"),"\\","/") .. "/vlc_DeleteFile_tmp.bat"
local f,err = io.open(tempf, 'a')
if err then
vlc.msg.dbg("DeleteFile: Failed to open vlcdel.txt for writing - " .. err)
end
end
end
if f~=nil then
f:write("del \"" .. dosfilename .. "\"\r\n")
f:flush()
f:close()
vlc.playlist.next()
else
vlc.msg.dbg("DeleteFile: Failed to open vlcdel.txt for writing - " .. err)
box = vlc.dialog("DeleteFile")
box:add_label("Failed to open a temp file for writing. I tried my best.")
box:add_button("CLOSE", deactive)
box:show()
end
end
function meta_changed()
end