local root_dir = "c:/temp" --physical path for storing temporary uploaded files
local timeout = 3600*3 --clean up uploaded files older than 3 hours
local removefiles = {}
local now = os.time()
if c_GetFileDir(root_dir) ~= nil then
for isdir,filename in c_GetFileDir(root_dir) do
if isdir == false and filename ~= nil and filename ~= "." and filename ~= ".." then
local filepath = root_dir.."/"..filename
if c_FileExist(filepath) then
if c_GetFileTime(filepath) + timeout < now then
table.insert(removefiles, filename)
end
end
end
end
end
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(root_dir.."/"..filename)
end
I wonder if you can help me, or point me in the right direction. I have been trying for several days to create a lua script to run in the Task Scheduler and:
1. Recognize when a file has been uploaded to a specific directory
2. email that file to my email address
3. Erase the file
I have written several batch files that accomplish this, but none of them will run from the Task Scheduler Program Execute Window (I have tried both bat and exe files)
The only thing even slightly unusual about the script is that, since the uploaded files are coming from a video camera which is motion-activated, the files are named Lobby-xxx-xxx-xxx where the x's are day-date-time stamps relating to the event. That means that the script can never know in advance what the exact name of the file is that has been uploaded.
Any advice or reference that anyone can provide would be greatly appreciated.
local filepath = "%PathName"
if string.find(filepath,"d:/ftp/test") then
c_SendMail("test@xxxx.com","a file has been uploaded","%Name uploaded a file '%FileName' ",filepath,"SMTPconfig")
c_RemoveFileDir(filepath)
end
We would like to flush the top Dir out every 60 days for all customers, but leave the bottom Dir untouched. Could this script be modified to achieve such a result?
Presumable we would have to run a loop passing in a different username as a variable to the root clean up dir every-time. It sounds way beyond my knowledge does anyone have anything similar they are willing to share?
local root_dir = "c:/temp" --physical path for storing temporary uploaded files
local timeout = 3600*3 --clean up uploaded files older than 3 hours
local removefiles = {}
local now = os.time()
if c_GetFileDir(root_dir) ~= nil then
for isdir,filename in c_GetFileDir(root_dir) do
if isdir == false and filename ~= nil and filename ~= "." and filename ~= ".." then
local filepath = root_dir.."/"..filename
if c_FileExist(filepath) then
if c_GetFileTime(filepath) + timeout < now then
table.insert(removefiles, filename)
end
end
end
end
end
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(root_dir.."/"..filename)
end
local root_dir = "D:/ftptest" --physical path for storing temporary uploaded files
local timeout = 3600*24*3 --clean up uploaded files older than 3 hours
local removefiles = {}
local now = os.time()
function checkfile(nowdir)
if c_GetFileDir(nowdir) ~= nil then
for isdir,filename in c_GetFileDir(nowdir) do
if isdir == false then
if filename ~= nil and filename ~= "." and filename ~= ".." then
local filepath = nowdir.."/"..filename
if c_FileExist(filepath) then
if c_GetFileTime(filepath) + timeout < now then
table.insert(removefiles, nowdir.."/"..filename)
end
end
end
else
checkfile(nowdir.."/"..filename)
end
end
end
end
checkfile(root_dir)
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(filename)
end
Thanks! It successfully deletes files from subdirs.
But I was actually more interested in the possibility of deleting the subdirs too.
Is that possible?
General idea is to have a dir where all files and subdirs are kept only for a predetermined time and the automatically deleted by a script.
Or maybe there is another logical solution, rather than a script?
local root_dir = "D:/ftptest" --physical path for storing temporary uploaded files
local timeout = 3600*24*3 --clean up uploaded files older than 3 hours
local removefiles = {}
local now = os.time()
function checkfile(nowdir)
if c_GetFileDir(nowdir) ~= nil then
for isdir,filename in c_GetFileDir(nowdir) do
if isdir == false then
if filename ~= nil and filename ~= "." and filename ~= ".." then
local filepath = nowdir.."/"..filename
if c_FileExist(filepath) then
if c_GetFileTime(filepath) + timeout < now then
table.insert(removefiles, nowdir.."/"..filename)
end
end
end
else
checkfile(nowdir.."/"..filename)
end
end
end
end
checkfile(root_dir)
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(filename)
end
Could somebody modify the script so it would delete all the subdirs aswell?
priit wrote:Thanks! It successfully deletes files from subdirs.
But I was actually more interested in the possibility of deleting the subdirs too.
Is that possible?
General idea is to have a dir where all files and subdirs are kept only for a predetermined time and the automatically deleted by a script.
Or maybe there is another logical solution, rather than a script?
local root_dir = "D:/ftptest" --physical path for storing temporary uploaded files
local timeout = 3600*24*3 --clean up uploaded files older than 3 hours
local removefiles = {}
local now = os.time()
function checkfile(nowdir)
if c_GetFileDir(nowdir) ~= nil then
for isdir,filename in c_GetFileDir(nowdir) do
if isdir == false then
if filename ~= nil and filename ~= "." and filename ~= ".." then
local filepath = nowdir.."/"..filename
if c_FileExist(filepath) then
if c_GetFileTime(filepath) + timeout < now then
table.insert(removefiles, nowdir.."/"..filename)
end
end
end
else
checkfile(nowdir.."/"..filename)
end
end
end
end
checkfile(root_dir)
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(filename)
end