Skip to main content
Known Participant
November 9, 2012
Question

Getting Filename without Path in a CFC

  • November 9, 2012
  • 3 replies
  • 847 views

Hi All,

I'm attempting to use a CFC/Event Gateway to get the filename of a file that has landed in a directory.

What I'm getting instead is the full path with the filename.

<cfcomponent>

<cffunction name="onAdd" access="public" returntype="void" output="false">

<cfargument name="CFEvent" type="struct" required="true">

<cfset var data = arguments.CFEvent.data>

<cfset var filename = arguments.CFEvent.data.filename>

</cffunction>

</cfcomponent>

I know that the above code isn't complete, but I think it's what 'counts' here.

The value that I'm getting back for the 'filename' variable is similar to this:

C:\WebSite\Some_Directory\Another_Directory\filename.ext

What I want is just the filename  (filename.ext) part of that line.

It appears that arguments.CFEvent.data.filename doesnt do it, and I've tried all kinds of combinations like  'filename', 'serverfile.filename', 'data.filename' and so on, but I must just be missing it.

I found a workaround for what I'm trying to do with the CFC,  but it would be a lot easier if I just knew what I need to use in the code to just pull the filename of the file that was dropped into the directory.  (Using the DirectoryWatcher)

If anyone can help out with how to do this,  it would be appreciated

I've been at this for ten hours and feel like Captain Noob right about now.

Thanks!

CFML_MANIAC

This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
November 20, 2012

CFML_MANIAC wrote:

The value that I'm getting back for the 'filename' variable is similar to this:

C:\WebSite\Some_Directory\Another_Directory\filename.ext

What I want is just the filename  (filename.ext) part of that line.

It appears that arguments.CFEvent.data.filename doesnt do it, and I've tried all kinds of combinations like  'filename', 'serverfile.filename', 'data.filename' and so on, but I must just be missing it.

You're missing nothing. It is simply that ColdFusion stores the file in the CFEvent struct as an absolute path. It makes sense, of course. The functionality is directory-watcher, so one should be able to derive information about the directory structure of the added file.

Inspiring
November 9, 2012
Inspiring
November 9, 2012

ListLast()