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.
eneuhar wrote:Was anyone able to modify this script so that it deletes the subdirectories as well?
Code: Select all
==========================================================================================
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)
end
end
end
else
checkfile(nowdir.."/"..filename)
end
end
end
end
checkfile(root_dir)
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(filename)
end
end
for subdir in c_GetDir("D:/TEST/") do
CallTheMaid(subdir)
end
==========================================================================================
End snippet
==========================================================================================
Code: Select all
-----------------------------------------------------------------------------------------------------------------
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()
for subdir in c_GetDir("D:/TEST/") do
CallTheMaid(subdir)
end
function CallTheMaid(subdir)
checkfile(root_dir)
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(filename)
end
end
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
-----------------------------------------------------------------------------------------------------------------
Code: Select all
----------------------------
local root_dir = "/ftproot/test/" .. subdir .. "/"
--physical path for storing temporary uploaded files
local timeout = 3600*1*1 --delete uploaded files older than 14 Days
local removefiles = {} --creates an empty table
local now = os.time()
for subdir in c_GetDir("/ftproot/test/") do
CallTheMaid(subdir)
end
function CallTheMaid(subdir)
checkfile(root_dir)
for _,filename in ipairs(removefiles) do
c_RemoveFileDir(filename)
end
end
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
Code: Select all
c_RemoveFileDir("/ftproot/test/user1")
c_MkDir("/ftproot/test/user1")
Wouldn't you need to check if the directory is empty first ?FTP wrote: ↑Sat Jan 11, 2020 3:38 am OK, actually you just need to remove that subfolder and then create a subfolder again:
Code: Select all
c_RemoveFileDir("/ftproot/test/user1") c_MkDir("/ftproot/test/user1")
but if I'm deleting files that are say 30 days and older and I have files in here that are only 2 days old the c_RemoveFileDir("/ftproot/test/user1") and c_MkDir("/ftproot/test/user1") will wipe all that out no ?