Task scheduler for cleaning up temporary uploaded files

You can share your Lua Scripts with everybody here.

Re: Task scheduler for cleaning up temporary uploaded files

Postby FTP » Thu Sep 06, 2012 3:17 am

eneuhar wrote:Was anyone able to modify this script so that it deletes the subdirectories as well?

Please check out the old posts carefully, we have already pasted the script for cleaning up root folder and all subfolders.
Site Admin
posts 1272
joined Tue Sep 29, 2009 6:09 am

Re: Task scheduler for cleaning up temporary uploaded files

Postby eneuhar » Thu Sep 06, 2012 3:09 pm

I tried the latest post of script, however it seems to only delete the files within subdirectories and not the folders themselves.
posts 6
joined Tue Aug 07, 2012 3:08 pm

Code modified to be called once for each sub-directory in a

Postby Guesseyder » Fri Apr 24, 2015 7:19 pm

I am attempting to modify this script so that I can load it into the task scheduler and every day at midnight it will launch to remove files and directories that are over 14 days old. I am using the Wing FTP server for Windows on a 64 bit Windows 2012 Server. I have separate directories set up for every user, and each user only has access to their own directory, and is blocked from all others.

Since I have given every client the ability to create their own sub-directories within their own directory, it makes it so that this script needs to be modified so that it will examine each of my user's directories and the sub-directories as a separate call to the script. This must be done in order to avoid it deleting the home directories of each user, which will be older than 14 days.

One method I could get this accomplished would be to call this script once for every account, with that account's directory set as the "local root_dir" variable. I fear this will become cumbersome as I will be required to add this to the task scheduler once for every client that exists, and every new client that I add to the server. I scoured the internet for an idea on how to get the Lua script to do this for each client's directory.

Most advice that I found for Lua scripting on the internet recommends that I install the LuaFileSystem library. Is this even possible to install and use with the Lua embedded in Wing FTP Server? I assumed it was not after I made a feeble attempt, and kept searching until I found another method. In my configuration, I have all user directories as a sub-directory of D:\Files. I want to point the Lua script to D:\Files as a starting point and have it loop through this code once for every directory found within.

I want this script to delete all files and sub-directory within each user's directory that are over 14 days old, and then do the same for the next user directory. I have cobbled this script together from the code listed on these forums, and from help files. Wing FTP server indicates that it has executed as it should, but it does not do anything. I fear that the 'built-in' functions that I am calling may not be included with Wing FTP server's implementation of Lua. If this is the case, and I do need to install a library, is this possible? Below is the script I cobbled together. I have made the code presented in this forum thread into a function named "CallTheMaid" so that it can be called once for every sub-directory found off of D:\Files. Can anyone tell me what I did wrong?

Thanks in advance,

Begin snippet
function CallTheMaid(subdir)
local root_dir = "D:/TEST/" .. subdir .. "/"
--physical path for storing temporary uploaded files
local timeout = 3600*24*14 --delete uploaded files older than 14 Days
local removefiles = {} --creates an empty table
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)


for _,filename in ipairs(removefiles) do

for subdir in c_GetDir("D:/TEST/") do
End snippet
posts 1
joined Fri Apr 24, 2015 6:48 pm


Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 1 guest