lpath path
echo path | lpath
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 ]
[ D:\bin\WA2LWinTools\lib ] [ fred@acme007 ][*sbshell*/cmd]: lpath data:\exports\weekly g:\exports\weekly
[ D:\bin\WA2LWinTools\lib ] [ fred@acme007 ][*sbshell*/cmd]: lpath r:\exports\weekly r:\exports\weekly
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
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.
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.