ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* escape io.fileseparator in Windows
@ 2021-11-03 18:49 Pablo Rodriguez via ntg-context
  2021-11-03 20:55 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2021-11-03 18:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Pablo Rodriguez

Dear list,

I have the following sample:

  \starttext
  \startluacode
  main_file = document.files[1]

  if file.pathpart(main_file) == "" then
    main_filename = file.nameonly(main_file)
    main_filename_win = main_filename
  else
    main_filename = file.pathpart(main_file):gsub(io.fileseparator, "/")
       .. "/" .. file.nameonly(main_file)
    docx_file = main_filename .. "-file.docx"
    epub_file = main_filename .. "-file.epub"
    if os.name == "windows" then
      main_filename_win = file.pathpart(main_file) .. io.fileseparator
        .. file.nameonly(main_file)
      docx_file_win = main_filename_win .. "-file.docx"
      epub_file_win = main_filename_win .. "-file.epub"
    end
  end

  if os.name=="windows" then
    context(docx_file_win)
    os.execute("copy " .. docx_file_win .. " aeae")
  else
    context(docx_file)
  end
  \stopluacode
  \stoptext

If I run it on Windows, context(docx_file_win) cannot deal with the
backslash, so I get:

  .document-file.docx

So it is impossible that os.execute may work with copy.

Running it with Linux, I get "./document-file.docx".

How can I get the io.fileseparator or escape the backslash in
main_filename_win above?

Many thanks for your help,

Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: escape io.fileseparator in Windows
  2021-11-03 18:49 escape io.fileseparator in Windows Pablo Rodriguez via ntg-context
@ 2021-11-03 20:55 ` Hans Hagen via ntg-context
  2021-11-04 14:54   ` Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen via ntg-context @ 2021-11-03 20:55 UTC (permalink / raw)
  To: ntg-context; +Cc: Hans Hagen

On 11/3/2021 7:49 PM, Pablo Rodriguez via ntg-context wrote:
> Dear list,
> 
> I have the following sample:
> 
>    \starttext
>    \startluacode
>    main_file = document.files[1]
> 
>    if file.pathpart(main_file) == "" then
>      main_filename = file.nameonly(main_file)
>      main_filename_win = main_filename
>    else
>      main_filename = file.pathpart(main_file):gsub(io.fileseparator, "/")
>         .. "/" .. file.nameonly(main_file)
>      docx_file = main_filename .. "-file.docx"
>      epub_file = main_filename .. "-file.epub"
>      if os.name == "windows" then
>        main_filename_win = file.pathpart(main_file) .. io.fileseparator
>          .. file.nameonly(main_file)
>        docx_file_win = main_filename_win .. "-file.docx"
>        epub_file_win = main_filename_win .. "-file.epub"
>      end
>    end
> 
>    if os.name=="windows" then
>      context(docx_file_win)
>      os.execute("copy " .. docx_file_win .. " aeae")
>    else
>      context(docx_file)
>    end
>    \stopluacode
>    \stoptext
> 
> If I run it on Windows, context(docx_file_win) cannot deal with the
> backslash, so I get:
> 
>    .document-file.docx
> 
> So it is impossible that os.execute may work with copy.
> 
> Running it with Linux, I get "./document-file.docx".
> 
> How can I get the io.fileseparator or escape the backslash in
> main_filename_win above?
(there are helpers for splitting names and combining paths)

- use locals
- wrap names in "" and use / : dir "c:/data"
- just use file.copy (with forward slashes), is faster too

so in the end there is no need to test for windows

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: escape io.fileseparator in Windows
  2021-11-03 20:55 ` Hans Hagen via ntg-context
@ 2021-11-04 14:54   ` Pablo Rodriguez via ntg-context
  2021-11-04 19:56     ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2021-11-04 14:54 UTC (permalink / raw)
  To: Hans Hagen via ntg-context; +Cc: Pablo Rodriguez

On 11/3/21 9:55 PM, Hans Hagen via ntg-context wrote:
> On 11/3/2021 7:49 PM, Pablo Rodriguez via ntg-context wrote:
>> [...]
>> How can I get the io.fileseparator or escape the backslash in
>> main_filename_win above?
> (there are helpers for splitting names and combining paths)
>
> - use locals
> - wrap names in "" and use / : dir "c:/data"

Many thanks for your reply, Hans.

I didn’t know that this was valid in Windows command prompt:

  command "d:/data/file.txt"

> - just use file.copy (with forward slashes), is faster too

copy was just a command sample, not the one I intend to use.

> so in the end there is no need to test for windows

I’m really suprised that Windows accepts slashes in paths.

Many thanks for your help again,

Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: escape io.fileseparator in Windows
  2021-11-04 14:54   ` Pablo Rodriguez via ntg-context
@ 2021-11-04 19:56     ` Henning Hraban Ramm via ntg-context
  0 siblings, 0 replies; 4+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2021-11-04 19:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm


> Am 04.11.2021 um 15:54 schrieb Pablo Rodriguez via ntg-context <ntg-context@ntg.nl>:
> 
> I’m really suprised that Windows accepts slashes in paths.

It does at least since Windows NT.

Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-04 19:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03 18:49 escape io.fileseparator in Windows Pablo Rodriguez via ntg-context
2021-11-03 20:55 ` Hans Hagen via ntg-context
2021-11-04 14:54   ` Pablo Rodriguez via ntg-context
2021-11-04 19:56     ` Henning Hraban Ramm via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).