lpath

Package: WA2L/WinTools 1.2.08
Section: Library Commands (3)
Updated: 30 April 2019
Index Return to Main Contents

 

NAME

lpath - expand a path containing labels

 

SYNOPSIS

WA2LWinTools/lib/lpath [ -h | -V ]

lpath path

echo path | lpath

 

AVAILABILITY

WA2L/WinTools

 

DESCRIPTION

the lpath command translates labels to drive letters in a given directory path.

This helps to be independent of drive letters that might change when an external drive is connected to an other USB port or to an other system.

Labels that can be handled by lpath look like drive letters with more then one character:

  data:\myData\Office
  import:\Import\Measurements
  USB-DISK1:\myImages\House
  _DISK1_:\myProjects\Internal\2019

A label can be a directory that exists on a drive, as:

  [ D:\bin\WA2LWinTools\bin ]
  [ fred@acme007 ][*sbshell*/cmd]: mkdir f:\USB-DISK1

or the disk name that can be set thru Windows™ Explorer:

  Explorer
  → right mouse-click on drive letter
  → General tab 
  → Disk-Icon: name
  → [ OK ]

The lpath command first searches all drives for an existing directory (the label directory), if not found, the disk names are checked. Whenever a match is found lpath returns the path with the drive letter hat is currently assigned to the disk with the given label.

When using directories as labels you can use an existing directory that only exists on the addressed drive or (better) an extra created directory that then serves as label.

The label directory can be hidden using command line:

  [ D:\bin\WA2LWinTools\bin ]
  [ fred@acme007 ][*sbshell*/cmd]: attrib +H f:\USB-DISK1

or the Windows™ Explorer:

  Explorer
  → right mouse-click on label directory 
  → Properties 
  → [x] Hidden
  → [ OK ]

 

OPTIONS

-h
help message.

-V
print program version.

path
path using labels or drive letters.

 

ENVIRONMENT

-

 

EXIT STATUS

0
no error.

4
usage printed.

5
version printed.

 

FILES

-

 

EXAMPLES

1) translate label to drive letter

  [ D:\bin\WA2LWinTools\lib ]
  [ fred@acme007 ][*sbshell*/cmd]: lpath data:\exports\weekly

  g:\exports\weekly

2) drive letters are not translated

  [ D:\bin\WA2LWinTools\lib ]
  [ fred@acme007 ][*sbshell*/cmd]: lpath r:\exports\weekly

  r:\exports\weekly

3) use lpath in a script

  set input=data:\exports\weekly

  for /f "tokens=*" %%r in ('echo !input!^| lpath') do set input=%%r

  if not exist "!input!" echo ERROR: input dir not found && exit /b 1

4) a more complete example script

The following script copies data from an 'out box' directory located on drive d:\ to the 'in box' directory of an USB stick labeled ACME-USB-STICK.

  @echo off
  rem
  rem WA2LWinTools/var/scripts/datacopy.cmd - example script to copy data
  rem
  rem [00] 30.04.2019 CWa       Initial Version
  rem
  
  rem usage: datacopy                    - copy data to ACME USB stick [scripts]
  
  rem Const
  rem
  setlocal EnableDelayedExpansion
  call:lset outbox "d:\data\ACME\out box"
  call:lset inbox  "ACME-USB-STICK:\in box"
  goto MAIN
  
  
  
  rem lset variable "path" -- set variable with resolved label path
  rem
  :lset
        set lset_path=%~2
        for /f "tokens=*" %%r in ('echo !lset_path!^| "%~dp0..\..\lib\lpath"') do set %1=%%r
        set lset_path=
  goto:eof
  
  
  
  rem MAIN -- main
  rem
  :MAIN
        echo.
        echo Copy files from OUT-BOX to IN-BOX on USB-Stick
        echo.
        echo OUT-BOX .....: !outbox! 
        echo IN-BOX ..... : !inbox! 
        echo.

        choice /C NY /M "Copy data?"
        if errorlevel 2 copy "!outbox!\*.*" "!inbox!\"
  
        endlocal
  rem MAIN

which generates the following output if the USB stick to transfer data is currently assigned to the G:\ drive:

  [ h:\ ]
  [ fred@acme007 ][*sbshell*/cmd]: datacopy
  
  Copy files from OUT-BOX to IN-BOX on USB-Stick
  
  OUT-BOX .....: d:\data\ACME\out box
  IN-BOX ..... : G:\in box
  
  Copy data? [N,Y]?Y
  d:\data\ACME\out box\concept.docx
  d:\data\ACME\out box\cost.xlsx
  d:\data\ACME\out box\plan.pdf
          3 file(s) copied.

The procedure :lset here is defined to conveniently set the given variable with the related path using the lpath command internally.

With the result that a path definition with a label (as: !inbox! variable) is translated to the related current drive letter and a path setting with a drive letter (as: !outbox! variable) is kept unchanged.

See https://ss64.com/nt/commands.html for excellent Windows™ cmd.exe scripting descriptions.

 

SEE ALSO

wintoolsintro(1), appstart(3), appstart.cfg(4), name(1), revision(1), usage(1), https://ss64.com/nt/commands.html

 

NOTES

-

 

BUGS

lpath cannot resolve disk names of network drives. However label directories on network drives can be used.

 

AUTHOR

lpath was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net . 

 

COPYRIGHT

Copyright © 2020 Christian Walther

This is free software; see WA2LWinTools/man/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 16:32:16 GMT, September 14, 2024