I've got an app (lndir) that expects a unix formated path instead of Windows ones.
Just fixing the path I can easily do using sed, but I don't know how to use the fixed path in script.
Input:
{sourcepath} and {destpath}
that's transformed using [sed "s#([a-zA-z]):#/cygdrive/\1#" | sed "s#\#/#g"] into /cygdrive/c/source
Output (as it should be):
lndir /cygdrive/c/source /cygdrive/c/target
Would be nice if anyone could help me getting the transformed form into a variable so I can use it in the lndir command. Thx in advance
There are a few ways you could do this. I think the best one would be to use some VBScript (or JavaScript, Perl, etc.) glue to convert the paths and then run the program.
See this post for some pointers & links about how the script could be called from Opus:
shout
I've never written any VBScript or similar. Kinda made it work with batch but it's pretty ugly. Maybe you've got an idea to make it nicer?
Below is the batch code I'm calling with "lnd.bat {filepath} {destpath} {file}":
@echo off
set source=%1
set dest=%2
if /i %source:~1,1% == %dest:~1,1% GOTO createlink
echo ERROR: Source and target drive must be identical.
pause
exit
:createlink
echo %1 | sed "s#\([a-zA-z]\):#/cygdrive/\1#" | sed "s#\\\#/#g" > d:\tmp\tmpFile
set /p cygsourcepath= < d:\tmp\tmpFile
cd %2
mkdir %3
cd %3
cd > d:\tmp\tmpFile
set /p destpath= < d:\tmp\tmpFile
echo %destpath% | sed "s#\([a-zA-z]\):#/cygdrive/\1#" | sed "s#\\\#/#g" > d:\tmp\tmpFile
set /p cygdestpath= < d:\tmp\tmpFile
lndir %cygsourcepath% "%cygdestpath%"