How to get the folder from a full file path?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the folder from a full file path?

Zhe Lee
I know %:p %:t thes things. But What I need now is not current folder I get a full file path from a regex match. 

And now I need to get the folder from this full path. 

I already Google a lot but can't find useful things all related about "%:t :p" things so how to make it. 

This is the code I use in the vimrc file. 

function! HandleURL()
  let s
:uri = matchstr(getline("."), '[a-zA-Z]*:\/[^ >,;]*')
  echo s
:uri
 
if s:uri != ""
   
if s:uri =~ '^http'
        silent
exec "AsyncRun chrome ".s:uri.""
   
else
       
""""""""""""""
       
"I want to use the totalcmd64 to run the folder of the s:uri here.
        """"""""""""""
        silent exec "
AsyncRun TOTALCMD64 ".s:uri.""
    endif
  else
    echo "
No URI found in line."
  endif
endfunction

Tnx in advance

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/db445162-2afa-4304-bb7b-6669c942a84c%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to get the folder from a full file path?

Gary Johnson-4
On 2020-01-27, Zhe Lee wrote:

> I know %:p %:t thes things. But What I need now is not current folder I get a
> full file path from a regex match. 
>
> And now I need to get the folder from this full path. 
>
> I already Google a lot but can't find useful things all related about "%:t :p"
> things so how to make it. 
>
> This is the code I use in the vimrc file. 
>
> function! HandleURL()
>   let s:uri = matchstr(getline("."), '[a-zA-Z]*:\/[^ >,;]*')
>   echo s:uri
>   if s:uri != ""
>     if s:uri =~ '^http'
>         silent exec "AsyncRun chrome ".s:uri.""
>     else
>         """"""""""""""
>         "I want to use the totalcmd64 to run the folder of the s:uri here.
>         """"""""""""""
>         silent exec "AsyncRun TOTALCMD64 ".s:uri.""
>     endif
>   else
>     echo "No URI found in line."
>   endif
> endfunction

I'm not sure I understand.  I think you're looking for fnamemodify()
and the ":h" modifier, perhaps this:

    silent exec "AsyncRun TOTALCMD64 ".fnamemodify(s:uri, ":h")

See

    :help fnamemodify()
    :help filename-modifiers

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200127171546.GD23965%40phoenix.
Reply | Threaded
Open this post in threaded view
|

Re: How to get the folder from a full file path?

Zhe Lee


On Tuesday, January 28, 2020 at 1:16:41 AM UTC+8, Gary Johnson wrote:
On 2020-01-27, Zhe Lee wrote:

> I know %:p %:t thes things. But What I need now is not current folder I get a
> full file path from a regex match. 
>
> And now I need to get the folder from this full path. 
>
> I already Google a lot but can't find useful things all related about "%:t :p"
> things so how to make it. 
>
> This is the code I use in the vimrc file. 
>
> function! HandleURL()
>   let s:uri = matchstr(getline("."), '[a-zA-Z]*:\/[^ >,;]*')
>   echo s:uri
>   if s:uri != ""
>     if s:uri =~ '^http'
>         silent exec "AsyncRun chrome ".s:uri.""
>     else
>         """"""""""""""
>         "I want to use the totalcmd64 to run the folder of the s:uri here.
>         """"""""""""""
>         silent exec "AsyncRun TOTALCMD64 ".s:uri.""
>     endif
>   else
>     echo "No URI found in line."
>   endif
> endfunction

I'm not sure I understand.  I think you're looking for fnamemodify()
and the ":h" modifier, perhaps this:

    silent exec "AsyncRun TOTALCMD64 ".fnamemodify(s:uri, ":h")

See

    :help fnamemodify()
    :help filename-modifiers

Regards,
Gary
 
 Thank you. It worked.  But after checking the  manual,  I think  `  silent exec "AsyncRun TOTALCMD64 ".fnamemodify(s:uri, ":p:h") `  It's a better way.  Am I right? 
 Thanks a lot for your help, I already find fnamemodify() before but seems my English is not good enough. 

 

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/8d90c146-f1b8-4401-8b5b-f15046b1a761%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to get the folder from a full file path?

Gary Johnson-4
On 2020-01-29, Zhe Lee wrote:

>
>
> On Tuesday, January 28, 2020 at 1:16:41 AM UTC+8, Gary Johnson wrote:
>
>     On 2020-01-27, Zhe Lee wrote:
>     > I know %:p %:t thes things. But What I need now is not
>     > current folder I get a full file path from a regex match. 
>     >
>     > And now I need to get the folder from this full path. 
>     >
>     > I already Google a lot but can't find useful things all
>     > related about "%:t :p" things so how to make it. 
>     >
>     > This is the code I use in the vimrc file. 
>     >
>     > function! HandleURL()
>     >   let s:uri = matchstr(getline("."), '[a-zA-Z]*:\/[^ >,;]*')
>     >   echo s:uri
>     >   if s:uri != ""
>     >     if s:uri =~ '^http'
>     >         silent exec "AsyncRun chrome ".s:uri.""
>     >     else
>     >         """"""""""""""
>     >         "I want to use the totalcmd64 to run the folder of the s:uri here.
>     >         """"""""""""""
>     >         silent exec "AsyncRun TOTALCMD64 ".s:uri.""
>     >     endif
>     >   else
>     >     echo "No URI found in line."
>     >   endif
>     > endfunction
>
>     I'm not sure I understand.  I think you're looking for fnamemodify()
>     and the ":h" modifier, perhaps this:
>
>         silent exec "AsyncRun TOTALCMD64 ".fnamemodify(s:uri, ":h")
>
>     See
>
>         :help fnamemodify()
>         :help filename-modifiers
>
>     Regards,
>     Gary
>
>  
>
>      Thank you. It worked.  But after checking the  manual,  I think  `  silent
>     exec "AsyncRun TOTALCMD64 ".fnamemodify(s:uri, ":p:h") `  It's a better
>     way.  Am I right? 

You're welcome.  I'm glad to hear that it worked.

If s:uri is a path name relative to the current directory, you would
be right.  However, if s:uri is a URI naming a file on your local
computer, then I would expect it to begin with "file:", for example:

    file:///path/to/file

The part after "file://" is already a full path name, so using ":p"
is not going to help.  It is not needed.

>  Thanks a lot for your help, I already find fnamemodify() before
> but seems my English is not good enough. 

You're welcome.  I think that ":help expand()" may have a better
explanation of file name expansion, but I don't know whether its
English is any easier to understand.

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200130081044.GB4379%40phoenix.