rejetto forum
May 26, 2012, 01:29:08 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: This forum is free, you do NOT need to register to post. But you may.
PROBLEMS? QUESTIONS? CLICK HERE!
Fill the survey!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Get path of currently selected file  (Read 567 times)
0 Members and 2 Guests are viewing this topic.
e4g
Occasional poster
*
Offline Offline

United States United States

Posts: 4


View Profile
« on: July 28, 2011, 04:39:39 PM »

Hello. I searched around the forum and couldn't find the answer to this question. I apologize ahead of time if it's already been answered (or is obvious).

Is it possible to get the path of the currently selected file in HFS so that it can be used in an external script? I've created a button that will only execute an external program if a single file is selected, but I want to reference that file in the code.

Example:

Code:
<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = "Select One File";
else
this.value = "Run"'/></form>
{.if|{.?view = Run.}|{:
{.exec|python script.py -e C:\pathto\selected\file.}
:}.}

Any help would be appreciated.
Logged
raybob
Tireless poster
****
Offline Offline

United States United States

Posts: 206



View Profile WWW
« Reply #1 on: July 28, 2011, 06:57:05 PM »

HFS includes a function for getting file names...  Try using it in your onclick.  You'll find it in the standard lib.js.

Code:
function getItemName(el) {
    if (typeof el == 'undefined')
        return false;
    // we handle elements, not jquery sets 
    if (el.jquery)
        if (el.size())
            el = el[0];
        else
            return false;
    // take the url, and ignore any #anchor part
    var s = el.getAttribute('href') || el.getAttribute('value');
    s = s.split('#')[0];
    // remove protocol and hostname
    var i = s.indexOf('://');
    if (i > 0)
        s = s.slice(s.indexOf('/',i+3));
    // current folder is specified. Remove it.
    if (s.indexOf(HFS.folder) == 0)
        s = s.slice(HFS.folder.length);
    // folders have a trailing slash that's not truly part of the name
    if (s.slice(-1) == '/')
        s = s.slice(0,-1);
    // it is encoded
    s = (decodeURIComponent || unescape)(s);       
    return s;
} // getItemName
Logged
e4g
Occasional poster
*
Offline Offline

United States United States

Posts: 4


View Profile
« Reply #2 on: July 28, 2011, 07:34:23 PM »

HFS includes a function for getting file names...  Try using it in your onclick.  You'll find it in the standard lib.js.

Code:
function getItemName(el) {
    if (typeof el == 'undefined')
        return false;
    // we handle elements, not jquery sets 
    if (el.jquery)
        if (el.size())
            el = el[0];
        else
            return false;
    // take the url, and ignore any #anchor part
    var s = el.getAttribute('href') || el.getAttribute('value');
    s = s.split('#')[0];
    // remove protocol and hostname
    var i = s.indexOf('://');
    if (i > 0)
        s = s.slice(s.indexOf('/',i+3));
    // current folder is specified. Remove it.
    if (s.indexOf(HFS.folder) == 0)
        s = s.slice(HFS.folder.length);
    // folders have a trailing slash that's not truly part of the name
    if (s.slice(-1) == '/')
        s = s.slice(0,-1);
    // it is encoded
    s = (decodeURIComponent || unescape)(s);       
    return s;
} // getItemName

Perhaps I'm missing something (I'm not very experienced with javascript) but how does that help me get the path to the selected file in a way that would allow it to be used in the macro? If I just needed the file name I could use "selectedFilesAsStr()" couldn't I? Can you perhaps give me an example of how this would work? Again, I appreciate the help.
Logged
e4g
Occasional poster
*
Offline Offline

United States United States

Posts: 4


View Profile
« Reply #3 on: July 29, 2011, 08:56:04 AM »

EDIT: Nevermind, that doesn't actually work.

« Last Edit: July 29, 2011, 10:03:07 AM by e4g » Logged
e4g
Occasional poster
*
Offline Offline

United States United States

Posts: 4


View Profile
« Reply #4 on: July 29, 2011, 10:28:00 AM »

Thanks.  I figured out part of it (I think) although there may be a better way.

This:

Code:
<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = "Select One File";
else
this.value = selectedFilesAsStr()'/></form>
{.if not|{.?view = Select One File.}|{:
{.notify|{.vfs to disk|{.?view.}.}.}
:}.}

gives me a notify bubble with the full path to the file. However, this:

Code:
<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = "Select One File";
else
this.value = selectedFilesAsStr()'/></form>
{.if not|{.?view = Select One File.}|{:
{.exec|notepad {.vfs to disk|{.?view.}.}.}
:}.}

does not open the selected file with notepad. Does this make sense?



EDIT: Solved it:

Code:

<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = 0;
else
this.value = selectedFilesAsStr()'/></form>
{.if not|{.?view.}||{:
{.exec|notepad|{.vfs to disk|{.?view.}.}.}
:}.}
« Last Edit: July 29, 2011, 11:17:29 AM by e4g » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!


Google visited last this page May 23, 2012, 01:32:21 AM