Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default String Manipulatio

    Hello All,

    I am trying to replace a specific pattern in a string, but could not get it
    working. Heres what I am trying to do:

    Say for ex: I have a string (which is actually a dynamically generated
    absolute file path)
    org_str="/abc/xyz/one/two/three/four.cfm"

    and for all such string I want to get rid of the first three directory levels,
    so in this case my new string should be:

    new_str="/two/three/four.cfm"

    So what I want is a regular expression which will parse my original string and
    remove the first three directory leves, giving me the rest of the string as it
    is.

    Has anybody done such kind of thing before !!! Please help, I have been trying
    this since the last couple of hours....

    All comments and responses appreciated.

    Thanks in advance.

    Regards,
    Tom

    sam504u Guest

  2. Similar Questions and Discussions

    1. Maintain query string and somehow auto refresh a pagewith that string intact
      I have a drill down where on page one the user selects criteria to narrow down the search for a speicific group of employees(like all hired between...
    2. #7056 [Com]: Setting string variables to value starting with '<' cause string to be empty.
      ID: 7056 Comment by: davidgjenkins at ntlworld dot com Reported By: tammy at synchronis dot com Status: Closed...
    3. string question: how to append x zeros to get fixed lenght string?
      "Bob Barrows" <reb_01501@yahoo.com> wrote in message news:uuhVv4mcDHA.656@tk2msftngp13.phx.gbl... newstring = Right("0000000" & i,8) ;-p
    4. Cannot create an object of type 'System.String[]' from its representation 'String[] Array'
      Hello, I am designing a .net custom control in VS.net 7.1 and my control exposes an array of strings which are supposed to be the items to show. To...
    5. String question: Returning portion of string with words surrounding highlighted search term?
      I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string,...
  3. #2

    Default Re: String Manipulatio

    Hi Group,

    Could anybody please get me through the solution to my problem ????


    sam504u Guest

  4. #3

    Default Re: String Manipulatio

    treat the string as a list delimited by "/":


    <cfscript>
    org_Str="/abc/xyz/one/two/three/four.cfm";
    tmpStr=org_Str;
    for (i=1; i LTE 3; i=i+1) {
    tmpStr=listDeleteAt(tmpStr,1,"/");
    }
    writeoutput(tmpStr);
    </cfscript>

    PaulH Guest

  5. #4

    Default Re: String Manipulatio

    Thanks Paul,

    The code was awesome, works perfect ... I didnt knew you could write stuff in cfscript.

    Thanks again really appreciate it ...

    Tom
    sam504u Guest

  6. #5

    Default Re: String Manipulatio

    btw you don't *have* to use cfscript.
    PaulH Guest

  7. #6

    Default Re: String Manipulatio

    Hi Paul,

    cfscript is fine .... thanks for the information though.

    One more question for you Paul. I was looking for a functionality where a user
    can make selections of files (by clicking checkboxs) and submit the form, the
    result of which I want is to download those files from the remote server on to
    the users local machine. Something like a "Save Target File as" option.

    I have CFMX running on a Linux box . Initially I was thinking of using CFFTP
    or CHTTP (get method) but none of this would allow me to download a file on
    clients machines , or will they ???? I am not sure, probably I am confused.

    Could you guide me in the matter?

    Thanks for all the help ....
    Tom

    <!--- This is how my Caller File looks --->

    <form method="post" action="process_file.cfm">

    <cfoutput query="select_wa_virusfile">
    <INPUT TYPE="CHECKBOX" NAME="selected"
    value="#select_wa_virusfile.vf_originalfile#"> <b>Filename:</b><a
    href="#select_wa_virusfile.vf_originalfile#">#sele ct_wa_virusfile.vf_originalfil
    e#</a>
    <b>Date:</b>#select_wa_virusfile.vf_modificationdate# <br />
    </cfoutput>
    <br /> <br />

    <INPUT TYPE="SUBMIT" VALUE="Download Now">


    --------------------------------------------------------------------------------
    -----------------------------------------------

    <!--- This is how I am trying to process the selected files for downloading
    --->

    <cfhttp
    method = "Get"

    url="http://#serverip#/#Quarantine_Location#/#unique_wa_virusfile.vf_quarantinef
    ile#"
    path=" ??????????? "
    file="#unique_wa_virusfile.vf_quarantinefile#">

    OR COULD HAVE BEEN using CFGET like this:

    <!--- ########Open connection --->

    <cfftp connection="Myftp"
    server="#serverip#"
    username="testing"
    password="testing"
    action="Open"
    stoponerror="Yes"
    passive="yes">

    <cfftp connection="Myftp"
    action="getFile"
    localFile=" ????????? "
    remoteFile="#tmp_Str#"
    stoponerror="Yes"
    passive="yes"
    failIfExists="No">

    <cfoutput> Status: #cfftp.returnValue# </cfoutput>

    Close the connection after every use
    <cfftp connection="Myftp"
    action="close"
    stoponerror="Yes">
    <p>Connection closed successfully:<cfoutput>#cfftp.succeeded#</cfoutput>


    But how will any of this work for downloading files from remote server to
    client machines. What do I specify in the "localfile" or "path" of cfftp and
    chttp respectively.

    While I was looking aroung on the Web I found a CF_FileManager custom tag
    developed by some third party company, which kind of does everything what i
    need, like a Pop up window where you can select files and: dowload, delete,
    rename etc but I dont wanna pay money for that.

    Do you know if theres anything which is built-in in CFMX where I can achieve
    this functionality.


    Thanks again

    sam504u Guest

  8. #7

    Default Re: String Manipulatio

    you could either build a page with simple http links to these files or use the cfcontent tag to push these files at the client.
    PaulH Guest

  9. #8

    Default Re: String Manipulatio

    Hello Paul,

    I went through the cfcontent documentaion, but it displays the content of the
    called page on the clients Web browser, which is not what I want. I want that
    the client should be able to save the file on his local machine, in that case I
    think I just have to make a Web page with the http links to the files, which he
    can "Right click" and choose "Save Target as" option.

    Correct me if I am wrong ....

    Tom

    sam504u Guest

  10. #9

    Default Re: String Manipulatio

    I think you were on a better track when you were wanting to do it with a
    regex.
    Try this:

    new_str = REReplace(org_str, "(/[^/]+){3}(.*)", "\2");

    --

    Adam
    Adam Cameron Guest

  11. #10

    Default Re: String Manipulatio

    yeah well regex has never been one of my strong points ;-) yes, this is indeed
    better.

    as far as cfcontent goes it might be something like this:

    <cfheader name="Content-Disposition" value="inline;
    filename=downloadFileNameGoesHere">
    <cfcontent type="MIMEtypeGoesHere" file="fullPathToFileGoesHere">


    PaulH Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139