how to find the subfolder in the director in coldfusion
I did in cfdirectory . It shows the all files not the folder
this is my code
<cfoutput>
<cfloop index = "i" from = "1" to = "3">
<cfdirectory
action = "list"
directory = "#myarray[i]#"
name = "files"
filter="*.*"
type="all">
<cfset d="#files.recordcount#">
<cfoutput>
#d#
</cfoutput>
</cfloop>
</cfoutput>
Related
For example I have array ads and inside it has images
ads
images
url = someurl
title = sometitle
*here I want to add prop = someprop
images
url = someurl
title = sometitle
*here I want to add prop = someprop
ads
images
url = someurl
title = sometitle
*here I want to add prop = someprop
Now I loop
<cfloop array="ads" index="i">
<cfloop array="i.images" index="j">
<cfif somecondition>
<cfset prop = 'yes'>
<cfelse>
<cfset prop = 'no'>
</cfif>
<cfset ArrayAppend(i.images[j],prop)> ???
</cfloop>
</cfloop>
I tried several things with the ArrayAppend, tried a StructAppend, but apparently I am unable to understand how I would go about.
You were close. You can simply set the prop on the item in the images loop. This is assuming that the items in the i.images array are structures.
<cfloop array="ads" index="i">
<cfloop array="i.images" index="j">
<cfif somecondition>
<cfset j.prop = 'yes'>
<cfelse>
<cfset j.prop = 'no'>
</cfif>
</cfloop>
</cfloop>
I'm not aware of an array attribute for cfloop, but I think this is what you're after
<cfloop from="1" to="#arrayLen(ads)#" index="i" step="1">
<cfset ads[i]["newprop"] = newpropvalue>
</cfloop>
How do you track template path in ColdFusion?
I.E.
I have the following folder and file structure
index.cfm
<cfset ArrayAppend(request.Trace, '/')>
<cfdump var=#request.trace#>
foo
index.cfm
<cfset ArrayAppend(request.Trace, '/foo/')>
<cfinclude template='../'>
bar
index.cfm
ArrayAppend(request.Trace,'/foo/bar/')>
<cfinclude template='../'>
When I call foo/bar/index.cfm,
request.Trace equals:
'/foo/bar/'
'/foo/'
'/'
How could I do this without specifically declaring each folder name?
Have a look at:
expandPath(".")
getBaseTemplatePath()
getCurrentTemplatePath()
CGI.CF_TEMPLATE_PATH
CGI.PATH_TRANSLATED
CGI.SCRIPT_NAME
If you want the template stack trace, use this:
<cfset templateTrace = []>
<cfset tagTrace = createObject("java","java.lang.Exception").init().TagContext>
<cfloop array="#tagTrace#" index="tagInfo">
<cfset templateTrace.add(tagInfo.Template)>
</cfloop>
<cfdump var="#templateTrace#">
This will output all templates passed up to this call.
Not ideal but this worked for me.
<cfset currentFile = GetCurrentTemplatePath()>
<cfset currentDir = GetDirectoryFromPath(currentFile)>
<cfset webroot = expandPath("/")>
<cfset m_Trace = Replace(currentDir, webroot , '\')>
<cfset ArrayAppend (request.Trace, m_Trace )>
The following code changes the body BG dependent on if the /home url is active else use a different BG. We have the pageID = 206 containing the /home BG image and pageID = 207 containing the else BG image. We currently have it setup this way so the client can go into the CMS and change the BG image without an issue.
However, the client would like the ability to add additional backgrounds and have them randomize. In theory I would add a page to the CMS and include the pageID and add randomize. I'm familiar with ColdFusion but this is a little over my head. Any input or direction would be greatly appreciated.
<cfsavecontent variable="HOME_BG">
<cfoutput>
<cfset includeID = '206'><cfinclude emplate='/PageInclude/PageInclude.cfm'/>
</cfoutput>
</cfsavecontent>
<cfset BG1 = getToken(HOME_BG,3, """") >
<cfsavecontent variable="COMM_BG">
<cfoutput>
<cfset includeID = '207'><cfinclude template='/PageInclude/PageInclude.cfm'/>
</cfoutput>
</cfsavecontent>
<cfset BG2 = getToken(COMM_BG,3, """") >
<body onload="checkCookie()" style="background-image: url(<cfoutput><cfif fpath EQ "home">#BG1#<cfelse>#BG2#</cfif></cfoutput>);">
I was looking for the ability to randomize between two different < cfset > but didn't find much luck.
Solution using an array and randrange
<cfset bgHomeIDArray = ArrayNew(1)> <!--- Create the array --->
<cfset ArrayAppend(bgHomeIDArray, 214)> <!--- Adds an array value --->
<cfset ArrayAppend(bgHomeIDArray, 215)> <!--- Adds an array value --->
<cfsavecontent variable="HOME_BG">
<cfoutput>
<cfset includeID = bgHomeIDArray[randRange(1, len(bgHomeIDArray))]> <cfinclude template='/PageInclude/PageInclude.cfm'/>
</cfoutput>
</cfsavecontent>
<cfset BG1 = getToken(HOME_BG,3, """") >
<cfset bgCommIDArray = ArrayNew(1)> <!--- Create the array --->
<cfset ArrayAppend(bgCommIDArray, 216)> <!--- Adds an array value --->
<cfset ArrayAppend(bgCommIDArray, 217)> <!--- Adds an array value --->
<cfsavecontent variable="COMM_BG">
<cfoutput>
<cfset includeID = bgCommIDArray[randRange(1, len(bgCommIDArray))]><cfinclude template='/PageInclude/PageInclude.cfm'/>
</cfoutput>
</cfsavecontent>
<cfset BG2 = getToken(COMM_BG,3, """") >
<body onLoad="checkCookie()" style="background-image: url(<cfoutput><cfif fpath EQ "home">#BG1#<cfelse>#BG2#</cfif></cfoutput>?03202014);">
I have one folder called misc which contains few sub folders and each sub folders has sub sub folders and files in it and I want to copy the sub folders, sub sub folders and its files in a called default folder.
I have tried this getting empty folder. And also I am wondering why Coldfusion doesn't have copy attribute in cfdirectory tag.
<cfset CurrentDirectory=GetTemplatePath()>
<cfset CurrentDirectory=ListDeleteAt(CurrentDirectory,ListLen(CurrentDirectory,"/\"),"/\")>
<cfset NewDirectory="#CurrentDirectory#\default">
<cfif NOT directoryExists(NewDirectory)>
<cfdirectory action="create" directory="#NewDirectory#">
</cfif>
<cfset strPath = ExpandPath("c:/wwwroot/test/misc") />
<cfdirectory action="list" directory="#strPath#" name="exDir">
<cfif exDir.type EQ 'File' >
<cffile action="copy" source="#strPath#" destination="#NewDirectory#" mode="777">
</cfif>
<cfif exDir.type EQ 'Dir'>
<cfdirectory action="create" directory="#NewDirectory#" mode="777">
</cfif>
<cfdump var = "#strPath#">
<cfdump var="#exDir#">
can anyone please let me know why I am getting empty folder ? any help would be appreciated!
directoryCopy() on cflib should do the job, or use cfzip
I have an application that uses a single signon for login in ColdFusion MX 7.0. It essentially
has a cfldap in the application.cfm. But the real issue is that I am trying to use a multi-file upload third party tool that submits to a coldfusion script with cffile and stuff in it.
Both the Flash based tool and the Java based tool are cauing an issue when I try a uploading more than 3 files at the same time. First they prompt the windows based login again. Even though I type in the credentials correctly, the upload process stops completely and only 1/2
files are uploaded.
The code for the Interface(form) for multi_file upload
<body>
<div id="EAFlashUpload_placeholder"></div>
<cfparam name="session.multiUploadError" default="">
<cfif session.multiUploadError neq "">
<font color="#FF0000"><em> <strong>Error Uploading File: </strong>
<cfoutput>#session.multiUploadError#</cfoutput></em></font>
<!--- ok. now wipe the error message clean for next time --->
<cfset session.multiUploadError = "">
</cfif><p></p>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var params = {
wmode: "window"
};
var attributes = {
id: "EAFlashUpload",
name: "EAFlashUpload"
};
var flashvars = new Object();
flashvars["uploader.uploadUrl"] = "http://iapreview.ars.usda.gov/admin/sp2.5/MultiFileUpload.cfm";
flashvars["viewFile"] = "TableView.swf";
flashvars["queue.filesCountLimit"] = "30";
flashvars["uploader.retrieveBrowserCookie"] = true;
swfobject.embedSWF("EAFUpload.swf", "EAFlashUpload_placeholder", "450", "350", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
</script>
</body>
The code for the backend ColdFusion script
<cftry>
<cfif isDefined("Form.Filedata")>
<cffile action="UPLOAD" filefield="Filedata" destination="#session.siteDirectory#\#session.Directory#" nameconflict="OVERWRITE">
<cfif right(cffile.clientFile, 3) neq "htm" and right(cffile.clientFile,4) neq ".htm">
<cfelse>
<cffile action="delete" file="#session.siteDirectory#\#session.Directory#\#cffile.clientFile#">
<cfset session.multiUploadError = " " & session.multiUploadError & " #cffile.clientFile# could not be uploaded, because html files are not permitted.<br> ">
</cfif>
<!---
<cffile action="APPEND" file="f:\sitepublisher_dev\sp2\juploadoutput.txt" output="#idx# - #session.siteDirectory#\#session.Directory#\#cffile.clientFile# (#cffile.fileSize#) at #cffile.timeLastModified#" addnewline="Yes">
--->
</cfif>
The file has not been saved. Please check destination folder exists and has read/write permissions.
<cftry>
<cfif isDefined("Form.Filedata")>
<cffile action="UPLOAD" filefield="Filedata" destination="#session.siteDirectory#\#session.Directory#" nameconflict="OVERWRITE">
<cfif right(cffile.clientFile, 3) neq "htm" and right(cffile.clientFile,4) neq ".htm">
<cfelse>
<cffile action="delete" file="#session.siteDirectory#\#session.Directory#\#cffile.clientFile#">
<cfset session.multiUploadError = " " & session.multiUploadError & " #cffile.clientFile# could not be uploaded, because html files are not permitted.<br> ">
</cfif>
<!---
<cffile action="APPEND" file="f:\sitepublisher_dev\sp2\juploadoutput.txt" output="#idx# - #session.siteDirectory#\#session.Directory#\#cffile.clientFile# (#cffile.fileSize#) at #cffile.timeLastModified#" addnewline="Yes">
--->
</cfif>
<cfcatch type="Any">
<cfoutput><eaferror>The file has not been saved. Please check destination folder exists and has read/write permissions.</eaferror></cfoutput>
</cfcatch>