Automatic decompress uploaded zip files

You can share your Lua Scripts with everybody here.
Post Reply
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Automatic decompress uploaded zip files

Post by FTP »

-- Description: Automatic decompress uploaded zip files
-- You should add the below scripts to the event manager -> FTP or HTTP OnFileUploaded
-- And I suppose you have installed WinRAR in the directory "C:\Program Files\WinRAR"
-- Author: Luke
-- Date: 2010-01-01

Code: Select all

local fname = string.gsub("%PathName", "\\","/")
local dpath = string.sub(fname,0,string.len(fname)-4)
local ext = string.lower(string.sub(fname,-4))

if ext == ".rar" or ext == ".zip" or ext == ".tgz" then 

 os.execute("C:\\Progra~1\\WinRAR\\WinRAR x -Y \""..fname.."\" \""..dpath.."\\\" ")

end
Image
duke2315
Posts: 1
Joined: Tue Mar 23, 2010 3:10 pm

Re: Automatic decompress uploaded zip files

Post by duke2315 »

This Script work great. The only question i have is if you can set this script to extract the files in the Archive to the root directory instead of creating another folder within the root directory.
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Automatic decompress uploaded zip files

Post by FTP »

OK, you can make it, just replace the line:

local dpath = string.sub(fname,0,string.len(fname)-4)

into this:

local dpath = string.sub(fname,0,string.len(fname)-string.find(string.reverse(fname),"/"))



BTW, you may write lua script by yourself, it is not very hard.
Post Reply