yadhi

Archive for the ‘ColdFusion’ Category

ColdFusion remove duplicate component in a list

In ColdFusion on April 16, 2007 at 12:02 am

I use this simple script for removing duplicate component in a list. below is the script


<cfoutput>
    <cfset List = "one,two,three,four,five,one,three">
    <cfset tempList = "">
    <cfloop list="#List#" index="i">
        <cfif not ListFind(tempList, i)>
            <cfset tempList = ListAppend(tempList, i)>
        </cfif>
    </cfloop>
    #tempList#>
</cfoutput>

just loop over the list and check weather new list contains the “index” component or not, if doesn’t contains, append it in that new list

ColdFusion simple copy file

In ColdFusion on April 12, 2007 at 5:28 pm

I write this script when my team have to debug our program at our client but don’t want got headache where the file is in the directory when we bring back to our office.

just a simple script, but it help me :D

here is the code

<cfoutput>
<cfparam name="defaultDirectory" default="semenpadang">
<form action="index.cfm" method="post">
<table>
<tr>
<td>Default Directory</td>
<td>:</td>
<td><input type="Text" name="defaultDirectory" value="#defaultDirectory#"></td>
</tr>
<tr>
<td>Full Path File Name</td>
<td>:</td>
<td><input type="Text" name="fullPathFileName" size="100"></td>
</tr>
<tr>
<td colspan="3"><input type="Submit" value=" Copy " name="btnSubmit"></td>
</tr>
</table>
</form>
<cfset Today = DateFormat(Now(), "yyyy-mm-dd")>
<cfset Expand_Path = ExpandPath("./")>
<cfset Expand_Path = Expand_Path & Today & "\">
<cfif IsDefined("FORM.btnSubmit")>
<cfset defaultDirectoryLocation = ListFindNoCase(FORM.fullPathFileName, FORM.defaultDirectory, "\")>
<cfset copyFullPathFileName = FORM.fullPathFileName>
<cfloop index="intI" from="1" to="#defaultDirectoryLocation - 1#">
<cfset copyFullPathFileName = ListDeleteAt(copyFullPathFileName, 1, "\")>
</cfloop>
<cfset directoryToCreate = ListDeleteAt(copyFullPathFileName, ListLen(copyFullPathFileName, "\"), "\")>
<cfset createdDirectory = "">
<cfloop list="#directoryToCreate#" index="directoryList" delimiters="\">
<cfset createdDirectory = ListAppend(createdDirectory, directoryList, "\")>
<cfif not DirectoryExists("#Expand_Path#\#createdDirectory#")>
<cfdirectory action="CREATE" newdirectory="#directoryList#" directory="#Expand_Path#\#createdDirectory#">
</cfif>
</cfloop>
<cffile action="COPY" source="#FORM.fullPathFileName#" destination="#Expand_Path##createdDirectory#\#ListLast(copyFullPathFileName,'\')#">
</cfif>
<cfdirectory action="LIST" name="listOfDirectory" directory="#Expand_Path#" recurse="Yes">
<cfquery name="listOfDirectory" dbtype="query">
SELECT * FROM listOfDirectory WHERE TYPE = 'File'
ORDER BY DIRECTORY, NAME
</cfquery>
<cfdump var="#listOfDirectory#">
</cfoutput>

or you can find it at http://docs.google.com/Doc?id=dhr2c3jq_9ffpf99