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.
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.
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
can you explain what your solution is doing... I'm just a beginner in js.
Since I posted that, I played with it some more in different browsers and got this:
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.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>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
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>
IE generally stands for Internet Explorer. Internet Explorer is a browser. Also, before you said you needed the path in this format:Originally Posted by jwd
"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
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).
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):
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.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>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
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%.
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:
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.Code:objFolder = objShell.NameSpace(path);
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks