Prev: regexp help
Next: Is there any direct way to interpret env vars read from file? Error in regexp
From: Ahmad on 5 Aug 2010 14:15 Hi, I am writing a TCL script that takes some file names from user. If these input file names exist in a relative place to current location, user may enter them in relative path to current location, for example: >> myScript.tcl ../file1 ../../abc/file2 xyz/file3 file4 cwb* My question is: What is the best way to deal with these arguments inside my script, in order not to have errors of "file cannot be found". Is there a way that can retrieve full path of files been passed at the beginning of running the script, and then, this full path could be used inside variable used in my script? Thanks, Ahmad
From: Jonathan Bromley on 5 Aug 2010 14:25 On Thu, 5 Aug 2010 11:15:43 -0700 (PDT), Ahmad <ahmad.abdulghany(a)gmail.com> wrote: >Hi, > >I am writing a TCL script that takes some file names from user. > >If these input file names exist in a relative place to current >location, user may enter them in relative path to current location, >for example: > >>> myScript.tcl ../file1 ../../abc/file2 xyz/file3 file4 cwb* > >My question is: > >What is the best way to deal with these arguments inside my script, in >order not to have errors of "file cannot be found". > >Is there a way that can retrieve full path of files been passed at the >beginning of running the script, and then, this full path could be >used inside variable used in my script? Does [file normalize] do what you need? -- Jonathan Bromley
From: Gerald W. Lester on 5 Aug 2010 14:27 Ahmad wrote: > Hi, > > I am writing a TCL script that takes some file names from user. > > If these input file names exist in a relative place to current > location, user may enter them in relative path to current location, > for example: > >>> myScript.tcl ../file1 ../../abc/file2 xyz/file3 file4 cwb* > > My question is: > > What is the best way to deal with these arguments inside my script, in > order not to have errors of "file cannot be found". > > Is there a way that can retrieve full path of files been passed at the > beginning of running the script, and then, this full path could be > used inside variable used in my script? Read the file man/help page. Pay attention to the section on the normalize subcommand. Of course, as long as you do not change the current working directory you should be able to use whatever the user entered without worrying if it was relative or absolute. -- +------------------------------------------------------------------------+ | Gerald W. Lester, President, KNG Consulting LLC | | Email: Gerald.Lester(a)kng-consulting.net | +------------------------------------------------------------------------+
From: Ahmad on 5 Aug 2010 14:35 Exactly, yes. Thanks, Ahmad On Aug 5, 11:25 am, Jonathan Bromley <s...(a)oxfordbromley.plus.com> wrote: > On Thu, 5 Aug 2010 11:15:43 -0700 (PDT), Ahmad > > > > <ahmad.abdulgh...(a)gmail.com> wrote: > >Hi, > > >I am writing a TCL script that takes some file names from user. > > >If these input file names exist in a relative place to current > >location, user may enter them in relative path to current location, > >for example: > > >>> myScript.tcl ../file1 ../../abc/file2 xyz/file3 file4 cwb* > > >My question is: > > >What is the best way to deal with these arguments inside my script, in > >order not to have errors of "file cannot be found". > > >Is there a way that can retrieve full path of files been passed at the > >beginning of running the script, and then, this full path could be > >used inside variable used in my script? > > Does [file normalize] do what you need? > -- > Jonathan Bromley
From: Donal K. Fellows on 6 Aug 2010 02:39 On 5 Aug, 19:27, "Gerald W. Lester" <Gerald.Les...(a)KnG-Consulting.net> wrote: > Of course, as long as you do not change the current working directory you > should be able to use whatever the user entered without worrying if it was > relative or absolute. But you can't know if two filenames refer to the same file before normalization; after normalization, simple string equality is enough. Strictly, you can't even tell after normalization without using [file stat] because of hard links, but that's a case where a file has two or more real names; if an equality test is important, stat is your only real tool available. But for surviving a changed directory, normalized names work fine as long as you're not using an old-style automounted NFS directory. The problem there was that the mount of the remote filesystem was hooked into the OS at the point where a symlink failed to be resolved, and using the absolute name would give you an unstable name (the mount would time-out, be unmounted, and not remounted for you). I remember this causing me so much grief back in the mid '90s when I was using a workstation where my home directory was automounted, and it wasn't just Tcl that had problems with that... Rather, it was *every* program that used getcwd() with one or two exceptions. Donal.
|
Next
|
Last
Pages: 1 2 Prev: regexp help Next: Is there any direct way to interpret env vars read from file? Error in regexp |