How to find and display directory files by partial name - list

I have a directory with the following files:
1245_cat.txt
6356_cat.txt
3564_it.txt
9867_it.txt
8437_xp.txt
6252_xp.txt
I am looking for a way to search and display file(s) based on partial name. For instance, if a user enters 1245, I would like to display 1245_cat.txt.
Here is what I have so far:
<cfset fileLocation = "\\doc_1\LOAD">
<cfdirectory directory = "#fileLocation#"
name = "archive"
type="file"
filter="*.txt"
action = "list">
Do I then create a list: archive_list of all returned files and use listContains(archive_list, "1245_cat.txt")?

Make the filter dynamic:
Let's say the search field is named "file_name", then
<cfparam name="form.file_name" type="string" default="">
<cfset myFilter = form.file_name & "*.txt">
<cfdirectory directory = "#fileLocation#" name="archive" type="file"
filter="#myFilter#" action = "list">

Related

How to Open Email in a Folder on Chrome

There is a shared public folder that users use to upload shared documents. Among the shared resources, some users have uploaded outlook email shortcuts to share amongst themselves.
I am attempting to have this email to open in Outlook when user is trying to open the resource on chrome, IE, etc.
Is this achievable?
Here is an example of an email that is saved in the share folder:
Example of an email.
The following code is what I am currently doing to have users the ability to view folders on their browsers and open and save documents:
<!--- The following if statement checks if the url wants to be downloaded. If it does, it creates a downloadable link. --->
<cfif structKeyExists(URL, 'method') and URL.method eq 'download'>
<cfset file_name = URL.name />
<cfset path = URL.path />
<!--- The following if statements determine file type. --->
<cfif findNoCase('.doc', file_name) or findNoCase('.odt', file_name) or findNoCase('.rtf', file_name) >
<cfset file_type = 'application/msword' >
<cfelseif findNoCase('.pdf', file_name) >
<cfset file_type = 'application/pdf' >
<cfelseif findNoCase('.xls', file_name) or findNoCase('.xlt', file_name) or findNoCase('.csv', file_name)>
<cfset file_type = 'application/vnd.ms-excel' >
<cfelseif findNoCase('.tif', file_name) >
<cfset file_type = 'image' >
<cfelseif findNoCase('.jpg', file_name) >
<cfset file_type = 'image/jpeg' >
<cfelseif findNoCase('.url', file_name) or findNoCase('.lnk', file_name) >
<cfset file_type = 'text/uri-list' >
<cfelseif findNoCase('.msg', file_name) >
<cfset file_type = 'text/uri-list' >
</cfif>
<!--- The following statements creates a downloadable link of the file. This is done by using cfheader and cfcontent --->
<cfheader name="Content-Disposition" value="inline; filename=#file_name#">
<!---Check if file type is available. If available, show type. --->
<cfif isDefined("file_type") >
<cfcontent type="#file_type#" file="#path#\#file_name#">
<!--- If file type is not found, display file anyways. --->
<cfelse>
<cfcontent file="#path#\#file_name#">
</cfif>
<cfabort>
</cfif>
This document describing the <cfcontent> tag states, "The following tag can force most browsers to display a dialog box that asks users whether they want to save the contents of the file specified by the cfcontent tag using the filename specified by the filename value. If the user selects to open the file, most browsers open the file in the related application, not the browser window.
<cfheader name="Content-Disposition" value="attachment; filename=filename.ext">
Some file types, such as PDF documents, do not use executable code and can display directly in most browsers. To request the browser to display the file directly, use a cfheader tag similar to the following:
<cfheader name="Content-Disposition" value="inline; filename=name.ext">"
The code in your question has this:
<cfheader name="Content-Disposition" value="inline; filename=#file_name#">
The key attribute is the value. You have "inline" which asks the browser to display the file directly. A value of "attachment" would allow the user to open the file with the default application for that type of file on their local machine.

How do I use cffile action= read the right way?

I have a table with my directory folder which contains all of my .txt files. Now I want that all .txt files are readable. I know I have to use <cffile action="read" ...>, but always something went wrong. How do I integrate the cffile tag into my script?
<cfparam name="name" default="0">
<h3>cfdirectory-Test</h3>
<cfdirectory
directory = "#ExpandPath('150903T')#"
action= "list"
name = "meinVerzeichnis"
sort = "name ASC, Type DESC, dateLastModified, Size"
type = "all"
filter = "*#name#*"
>
<cftable border="2"
query="meinVerzeichnis"
htmltable
colheaders>
<cfcol
header="Name:"
text="#Name#">
<cfcol
header="Type:"
text="#Type#">
<cfcol
header="Größe:"
text="#Size#">
<cfcol
header="Letztes Modifikationsdatum:"
text="#dateLastModified#">
</cftable>
<form method="get" action="msuche.cfm">
<button type="submit">Zurück</button>
</form>

how to find the subfolder in coldfusion

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>

Using <cfinclude> with this.mapping

In my application I have a header and footer include. In my Application.cfc I've set up a function that names my application and sets mapping.
<cfcomponent output="no">
<cfset this.name = "thesitename">
<cfset this.datasource = "thesitedatasource">
<cfset this.rootDir = getDirectoryFromPath(getCurrentTemplatePath()) />
<cfset this.mappings = structNew()>
<cfset this.mappings["/planning"] = "#this.rootDir#planning/" />
<cfset this.mappings["/images"] = "#this.rootDir#images/" />
<cfset this.mappings["/includes"] = "#this.rootDir#includes/" />
<cfset this.mappings["/js"] = "#this.rootDir#js/" />
<cfset this.mappings["/portfolio"] = "#this.rootDir#portfolio/" />
</cfcomponent>
If I have a page in a subdirectory like this: planning/index.cfm the <cfinclude> can't locate anything in the images folder when I use the following path: <li class="imagelink"><img src="/images/facebook.png"></li>
Pages in the root directory don't have a problem.
If I understand correctly, the problem has to do with the mapping doesn't take place prior to the include being called, or something like that... How do I get the mapped paths to work properly in my include?
ColdFusion mappings are completely separate from a web server 'alias' or 'virtual directory'. In order for your code to work, you will need to add a web server mapping, 'alias' in Apache or 'virtual directory' in IIS, named 'images' that points to the directory where you keep the images.
The 'images' ColdFusion mapping will only work in ColdFusion - for example, when creating an object, you could use createObject( "component", "images.image") (assuming of course that you had a CFC named Image in that diectory.

cffile not working at all

cffile is giving a head ache now.
My cfm is like this -
`
<cfif session.ismac and session.browsermake eq "firefox">
<cfset size = "55">
</cfif>
<cfset onChange = "document.frmMain.submit1.disabled = true;setdisplayname(this,this.form.dummy);">
<cfif displayname EQ "">
<cfset size = "document.frmMain.submit1.disabled = true;setdisplayname(this,this.form.displayname);">
</cfif>
<cfinput type="file" name="File#thisUploader#" id="File#thisUploader#" size="#size#" onKeyPress="return false;" onchange="#onChange#">
`
and in my cfc the code is like this -
<cffile accept="image/*" action="upload" destination="#application.artworkfilepath#\bulkuploads\#session.loginname#\#form.category#\" filefield="form.File#thisUploader#" nameconflict="makeunique">
and if I dump - <cfoutput>
You uploaded #cffile.ClientFileName#.#cffile.ClientFileExt#
successfully to #cffile.ServerDirectory#.
</cfoutput>
<cfabort>
I get corrct things and no error.
But when i look into the folder there is nothing.
Anyidea? I have added the dump of cffile now. What do you make out of it?
cfform code is like this <cfform id="frmMain" name="frmMain" action="process_multi.cfm" enctype="multipart/form-data" target="_self" method="post">
do a fileExists() directly after the statement and let us know what that says...
you don't have a directorywatcher on the directory do you?
Your cffile nameconfict attribute is set to makeunique, which tells ColdFusion to rename the file to something new when it arrives at the server--if the file already exists.
However, you are using cffile.ClientFileName and cffile.ClientFileExt to refer to the file file--which maps to the unchanged file name as it was received during upload.
Change your code references to cffile.ServerFileName and cffile.ServerFileExt for the final renamed result.