2013-05-31 66 views
2

任何人都可以通過建議在ColdFusion中提取.7z文件的函數來幫助我嗎?我使用基於ColdFusion 10和cfscript的代碼。確實,我們有cfzip標籤,但它只提取.zip.jar文件。在Coldfusion中提取7z文件

回答

0

功能來的unrar在給定的目標.rar文件..使用cfexecute標籤在命令行中運行exe文件的RAR

<cffunction name="Unrar" access="public" returnType="boolean" output="false"> 
    <cfargument name="archivefile" type="string" required="true">  
    <cfargument name="destination" type="string" required="true"> 
    <cfset var exeName = ""> 
    <cfset var result = ""> 
    <cfset var errorresult = ""> 


    <cfif not fileExists(arguments.archivefile)> 
     <cfthrow message="Unable to work with #arguments.arvhiefile#, it does not exist."> 
    </cfif> 

    <cfif findnocase(".rar",arguments.archivefile)> 

     <cfset var exeName = expandpath("WinRAR\rar.exe")> 
     <cfset var args = []> 
     <cfif directoryExists(#arguments.destination#)>    
      <cfset args[1] = "x +o"> 
     <cfelse> 
      <cfset directoryCreate(#arguments.destination#)>     
      <cfset args[1] = "x"> 
     </cfif> 
     <cfset args[2] = arguments.archivefile> 
     <cfset args[3] = "#arguments.destination#">   
    </cfif> 
    <cfexecute name="#exeName#" arguments="#args#" variable="result" errorvariable="errorresult" timeout="99" /> 

    <cfif findNoCase("OK All OK", result)> 
     <cfreturn true> 
    <cfelse> 
     <cfreturn false> 
    </cfif>   
</cffunction>