Question

Why do I get a \ after GETDIRECTORYFROMPATH(#CGI.CF_TEMPLATE_PATH#)

Asked by: dmatthews

I am using GETDIRECTORYFROMPATH(#CGI.CF_TEMPLATE_PATH#)and it returns the proper directory except that it has a \ at the end. I.E. c:/www/test/\. Anybody know why this happens?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-03-27 at 15:57:15ID20565804
Tags

getdirectoryfrompath

Topic

ColdFusion Application Server

Participating Experts
5
Points
250
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. path not correct?
    I wonder if someone would be so kind and have a look at metar.txt at http://trans-direct.net/testing/ and could tell me what might be wrong with my path. Everything I tried does not seem to work. It always says that metar.html (the template file) was not found. Command line...
  2. path not correct?
    I wonder if someone would be so kind and have a look at metar.txt at http://trans-direct.net/testing/ and could tell me what might be wrong with my path. Everything I tried does not seem to work. It always says that metar.html (the template file) was not found. Command line...
  3. Path of Template File
    A friend in France posed this question: There is an .XLT file stored on a network drive. When someone opens a new file based on this Template, and the user saves the new file, we want the default directory to be whichever directory the template was originally located. Fo...
  4. looking for template path
    How can I find out where a template file should be? and how do I find out if there are any ColdFusion mapping involves with this file. I have a problem with this statement: <cf_catalogtag category="#ID#" catalog="category,thumbnail,picture,path,description,...
  5. Word Template path
    I need to identify any word documents that have template paths that refer to a network drive. opening the docs and querying the attachedtemplate works fine until I come across instances where the network template has been deleted. Word seems to substitute the default local p...
  6. Getting the template path
    I have created an Excel 2003 template. When I create a new workbook from this template I need to find the location of this template. The "ThisWorkbook.Path" does not help me because the Path gives me the path to the new workbook (if it is saved) and not the path to ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: anandkpPosted on 2003-03-27 at 20:28:15ID: 8222664

weird,

can i have a look at ur code - i guess shld be some typo .. i dont know - will need to take a look

let me know

K'Rgds
Anand

 

by: anandkpPosted on 2003-03-27 at 20:36:34ID: 8222697

this works fine for me

<CFOUTPUT>
#GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH)#
</CFOUTPUT>

giving me :
D:\My Doc\Reference\My-ColdFusion\MyUitlity\TEST\

K'Rgds
Anand

 

by: jladams97Posted on 2003-03-27 at 23:45:07ID: 8223233

What version of CF are you using?  I'm using CFMX and all the comments below are relevant to results achieved with CFMX and may differ from results achieved with other versions of CF.

1.  If you put what you have written directly inside a <cfoutput></cfoutput> tag pair so that you have <cfoutput>GETDIRECTORYFROMPATH(#CGI.CF_TEMPLATE_PATH#)</cfoutput>, you'll get something like:

GETDIRECTORYFROMPATH(C:\Inetpub\wwwroot\test\ztestexe001.cfm)

That leads me to wonder if you're instead assigning that code to a variable.  Are you, if so, please provide the complete line of code.

2.  If you move your #s to the outside and put them in a <cfoutput></cfoutput> tag pair so that you have <cfoutput>#GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH)#</cfoutput>, you should get something like:

C:\Inetpub\wwwroot\test\

3.  Note that the correct output includes backslashes and no slashes.  You said your output includes slashes.  That's a red flag right there.  I can't say how it is related to the issue of you getting one lone backslash at the end, but I bet there is some relation.

4.  Note that the correct output has a capital C.  If you're on a machine with a drive that is actually named C and not c, then that's what the output should be.

5.  How about using CGI.PATH_TRANSLATED instead of CF_TEMPLATE_PATH?  Try <cfoutput>#GETDIRECTORYFROMPATH(CGI.PATH_TRANSLATED)#</cfoutput> and you should get this:

c:\inetpub\wwwroot\test\

5.  Note that the correct output has a lowercase c. I'm not sure why it is different from the output of <cfoutput>#GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH)#</cfoutput>.

Josh

 

by: dash420Posted on 2003-03-28 at 00:25:10ID: 8223374

it quite strange.
I tried with one test.cfm it is giving correct path

F:\inetpub\cfusion\cftest\dash\

 

by: dmatthewsPosted on 2003-03-28 at 05:35:27ID: 8224590

I had <CFSET Path=GETDIRECTORYFROMPATH(#CGI.CF_TEMPLATE_PATH#)>. I think the extra \ was due to the fact that it is running on an apache web server. I read that in some article somewhere. The purpose of this code was to do some login verification. So I do <CFIF (CGI.CF_TEMPLATE_PATH IS NOT "#PATH1#login.cfm") AND (CGI.CF_TEMPLATE_PATH IS NOT "#PATH1#login2.cfm")> that to make sure that the user is coming from the login pages before I set a session variable. This code was in an application.cfm page.

I ended up doing a removechars function on path and using that variable called path1. I am am still curious as to why that happens however.

An article here http://www.systemanage.com/cff/cftips7.cfm says that it puts the extra \ due to the fact that it is a unix system.

 

by: HamdyHassanPosted on 2003-03-28 at 06:06:02ID: 8224780

That's what I expected when I read the question, "IT's UNIX"

at unix world it's "/" to seprate directories, not "\" as windows.

 

by: dmatthewsPosted on 2003-03-28 at 06:08:11ID: 8224793

Funny that it only made the last slash a back slash and not all the other ones however.

 

by: weeezlPosted on 2003-03-28 at 09:19:22ID: 8226310

ColdFusion seems to like to reinterpret the direction of slashes. You can put them in either way or even mixed for some functions and CF will process it anyway.

Here's an easy catch:
#replace(GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH),'\','')#

 

by: dmatthewsPosted on 2003-03-28 at 09:34:34ID: 8226457

I did the same thing using the removechars function but your answer will work so you get the points.

 

by: jladams97Posted on 2003-03-28 at 10:32:00ID: 8226873

Sure that solution will work on a UNIX box--but guess what it does on a Windows box?  If you're sure you'll *never* port or reuse your code on a Windows box then you're in good shape; otherwise, you should *not* use the code weeezl gave you.  This code, on the other hand, should never cause any harm:

#replace(GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH),'/\','')#

Josh

 

by: jladams97Posted on 2003-03-28 at 10:33:02ID: 8226880

My mistake!  That should be:

#replace(GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH),'/\','/')#

Josh

 

by: dmatthewsPosted on 2003-03-28 at 10:53:52ID: 8227002

That would give me an extra / wouldn't it. It would turn c:/www/test/\ into c:/www/test// wouldn't it? Needless to say I will be sure to be careful if I use it on a windows system. I won't have this problem on a windows system anyway because it will not add the \ on a windows system.

 

by: jladams97Posted on 2003-03-28 at 11:15:16ID: 8227134

No, that won't give you an extra slash.  All it will do is replace the first instace of the string "/\" with the string "/" (and note that if you wanted to check for all instances of the string "/\" you'd use #replace(GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH),'/\','/', 'all')#).  So effectively what it will end up doing is removing the trailing backslash.

You're right--you won't have this problem on a Windows system because it won't add the trailing backslash.  But if you port weeezl's code (#replace(GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH),'\','')#) over to a Window's system, it will produce an undesired result:  instead of removing a trailing backslash, it will remove the first backslash, specifically the slash after the drive letter and colon.  The reason for this is that weeezl's code searches for the first backslash and replaces it with the empty string.  Simply put:  on a Windows system, weeezl's code will break stuff.  The alteration I suggested won't break anything because instead of searching for a backslash alone, it searches for a slash followed by a backslash.  Since that string will not exist in GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH) on a Windows machine, the code I gave will not make any changes to the result of GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH) on a Windows system, thereby not breaking anything.

Josh

 

by: anandkpPosted on 2003-03-28 at 20:58:21ID: 8229400

I hope this is not a timebeing makeover solution as it may behave differently in different situations .. causing undesired results ...

Identify the root cause & then go ahead with it ...

K'Rgds
Anand

 

by: jladams97Posted on 2003-03-29 at 07:55:13ID: 8230702

dmatthews--please read and respond!

Anand--

I'm not sure what it is that you're saying may behave differently in different situations.  If you're talking about the value in GETDIRECTORYFROMPATH(CGI.CF_TEMPLATE_PATH), we know that is different on Windows and UNIX.  In terms of the best way to approach the issue, I agree that identifying the root cause is the best way to go.  And as I'm thinking about it, I think I might have an idea about what that root cause is.  But let me hold that for a second and get back to what you were saying.  But though identifying the root cause may be the best way to go, if for whatever reason it can't be done, another solution has to be reached.  Now, that solution has to be as robust as possible--as you point out, a "timebeing makeover solution" is not a good one.  And this is where I come back to the question of what it is you question as such a solution.  The solution weeezl gave is, in my opinion, such a solution as it will cause different results on UNIX and Windows.  The solution I gave is not, in my opinion, such a solution as it will not cause different results on UNIX and Windows (let me note that the actual result will not be the exact same on UNIX and Windows as the UNIX result will contain slashes and the Windows result will contain backslashes but I believe that this is the desired result because that is how paths on those OSs are represented--someone correct me if I am wrong).  My solution is only capable of causing problems if the string "/\" is a legitimate part of a disk path on an OS.  If that string is never legitimate on any OS (and I think it isn't) then my solution is okay.

Okay, dmatthews--I hope you're still with me here.  I'd like you to test the following code and give me your results, please.  I do not have UNIX box on which to test or I would test this myself.  Thanks!  Here's the code:

<cfoutput>#CGI.CF_TEMPLATE_PATH#</cfoutput><br>
<cfoutput>#GetDirectoryFromPath(CGI.CF_TEMPLATE_PATH)#</cfoutput><br>
<cfoutput>#Replace(GetDirectoryFromPath(CGI.CF_TEMPLATE_PATH), '/', '\', 'all')#</cfoutput><br>
<cfoutput>#GetDirectoryFromPath(Replace(CGI.CF_TEMPLATE_PATH, '/', '\', 'all'))#</cfoutput><br>

Please copy and paste the results into a post in this thread.  Please also tell me what version of CF you're running.

Do the results you get look something like this:

C:/Inetpub/wwwroot/test/ztestexe001.cfm
C:/Inetpub/wwwroot/test/\
C:\Inetpub\wwwroot\test\\
C:\Inetpub\wwwroot\test\

If your results look like that then here's what I think is going on:  ColdFusion bug, baby!  The last two lines of the output *should* look exactly alike; if they don't, ColdFusion must have a bug.  The reason they should look exactly alike is that they're doing the same operations on the variable--they're just doing the operations in a different order.  But these particular operations should be transitive and the order shouldn't matter.  If the order does matter, that to me is a bug with CF.

If the results you get look like what I wrote above, here's my explanation:  when CF does GetDirectoryFromPath on a variable, it removes the trailing backslash along the way but it replaces it before it finishes.  In Windows, this works fine.  But in UNIX, where there are no backslashes, it does not work.  Instead, for some reason the trailing slash is not removed and the appended backslash is just wrong!  That could be a little off; the truth could instead be even more simple--when GetDirectoryFromPath has completed its operations it does one last thing:  it looks for a trailing backslash and if it isn't there it appends it.  But regardless, if either of those theories is correct the output shown above is what you should get on UNIX.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...