Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: I need a parsed path

  1. #1
    Join Date
    Nov 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need a parsed path

    Can anyone tell me how or what to use to get a directory path. I tried using "%THISDIRPATH%" but its not parsed out. example "c:\windows\web" is "c:WindowsWeb". The function I am using requires the path to be just as if you typed it.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <script type="text/javascript">
    var path=location.href.substring(0, location.href.lastIndexOf('/'))
    path=/^http/.test(path)? path : path.replace(/\//g, '\\').replace(/^file..../, '')
    alert(path)
    </script>
    Last edited by jscheuer1; 11-08-2005 at 05:33 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks but can you explain

    can you explain what your solution is doing... I'm just a beginner in js.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Since I posted that, I played with it some more in different browsers and got this:

    Code:
    <script type="text/javascript">
    /*  John Davenport Scheuer */
    var path=location.href.substring(0, location.href.lastIndexOf('/'))
    if(!/^http/.test(path)){
    path=path.replace(/\//g, '\\').replace(/^file..../, '').replace(/^ocalhost./, '')
    path=path.charAt(0).toLowerCase()+path.substr(1)
    }
    alert(path)
    </script>
    The first line takes the location.href of the page which, when live, is a text string of exactly what is in the address bar and strips off the trailing "/filename.ext" from it using the substring method. It takes the part of the string from the beginning (0) up to but not including the last / (location.href.lastIndexOf('/')). Locally this text string varies among browsers and depending upon how you got to the page. If the page is live we don't need to do anything else to it. If it isn't live (doesn't start with "http", as determined using the test() method) we replace() all /'s with \'s, strip away the typical prefixes (replacing them with nothing), if present, and change the drive letter to lower case by plucking it from what is now the beginning using charAt(0) and toLowerCase(), then add on the rest of the current remaining string using substr(1) - strings begin at 0.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Additional info

    The application that I'm using is in WebView on a pc, it's not running under a browser, just IE. What I'm trying to do is to add a function that returns the number of files when a folder is selected. I have the Function, what I need is a way to get the path to the current selected folder and pass it to the function. This is the function I am trying to convert:

    </script>

    <script language="JScript">
    function fnFolderObjectItemsJ()
    {
    var objShell = new ActiveXObject("Shell.Application");
    var objFolder = new Object;

    objFolder = objShell.NameSpace("C:\\WINDOWS\WEB");
    if (objFolder != null)
    {
    var objFolderItems = new Object;

    objFolderItems = objFolder.Items();
    return objFolderitems;
    }
    }
    </script>

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by jwd
    it's not running under a browser, just IE
    IE generally stands for Internet Explorer. Internet Explorer is a browser. Also, before you said you needed the path in this format:

    "c:\windows\web"

    Now you are saying that you need:

    "C:\\WINDOWS\WEB"

    There is a bit of a difference. Taking what you have and blending it with my code:

    Code:
    <script language="JScript">
    function fnFolderObjectItemsJ()
    {
    var path=location.href.substring(0, location.href.lastIndexOf('/'))
    if(!/^http/.test(path)){
    path=path.replace(/\//g, '\\').replace(/^file..../, '').replace(/^ocalhost./, '')
    path=path.charAt(0)+path.charAt(1)+'\\'+path.substr(2)
    path=path.toUpperCase()
    }
    
    
    var objShell = new ActiveXObject("Shell.Application");
    var objFolder = new Object;
    
    objFolder = objShell.NameSpace(path);
    if (objFolder != null)
    {
    var objFolderItems = new Object;
    
    objFolderItems = objFolder.Items();
    return objFolderitems;
    }
    }
    </script>
    Last edited by jscheuer1; 11-08-2005 at 10:11 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Nov 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default sorry about that

    I mean explorer (XP).... I'm modifing a .htt templet that runs when you specify "use existing customization templet" on the drop down list in folder properties(customize tab).

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Ah well, I am not very familiar with that type of thing. However, if it truly is JScript, give this a try (note the comment, in green, about quoting the % delimited variable):

    Code:
    <script language="JScript">
    function fnFolderObjectItemsJ()
    {
    var path=%THISDIRPATH%  // %THISDIRPATH% may need to be quoted: "%THISDIRPATH%"
    path=path.replace(/:/, ':\\').replace(/([A-Z])/g, '\\$1').toUpperCase()
    
    var objShell = new ActiveXObject("Shell.Application");
    var objFolder = new Object;
    
    objFolder = objShell.NameSpace(path);
    if (objFolder != null)
    {
    var objFolderItems = new Object;
    
    objFolderItems = objFolder.Items();
    return objFolderitems;
    }
    }
    </script>
    Also, this will probably not work with directory names that do not start with a letter. There may be other bugs say, in the case where a directory name includes a space character or upper case letters in its name on disk.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Nov 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I pasted your function into the htt file and used
    data = fnFolderObjectItemsJ();
    to call the function, however the contents of data is "undefined". Also you were right about needing quotes arround the %THISDIRPATH%.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, we are now beyond the scope of my knowledge in this area. It would be great if we had a way of seeing what the path variable contained just before it was plugged into:

    Code:
    objFolder = objShell.NameSpace(path);
    One thing you should check out, if you haven't already is the MS Windows Shell Reference. It looks like this is what you are using, as opposed to JScript.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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