Re: how to judge whether a path is relative path or absolute path

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Nod, this one is oddly tough; here's two solutions I've used over the
years (word-wrap almost certainly going to be a problem below) -

:: 2 approaches below

:: ------------------------

:: FIRST

:: Example script that demonstrates how to count characters by piping
UNICODE output through
:: non-UNICODE console filters

@echo off
setlocal ENABLEDELAYEDEXPANSION

:: Space char. substitution below (I used a period) was necessary as
when %* or %VAR% is expanded by
:: the for-in-do below, it concatenated any number of sequential spaces
to 1 space destroying an
:: accurate count
set VAR=%*
set VAR=%VAR: =.%

if "%VAR%"=="" (
set CNT=0
) else (
for /f "delims=[] tokens=1" %%l in ('cmd /u /c echo %VAR%^| find /v /n
""') do (
set /a CNT=%%l-3
)
)

echo %CNT%

goto :EOF

:: -------------------------

:: SECOND

:: Uses byte size within a temporary file

:getLEN
set LENGTH=0
set /p=%1>%tempFILE%<nul
for /f %%l in ("%tempFILE%") do set LENGTH=%%~zl
goto :EOF


--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Tom Lavedas" <tglbatch@xxxxxxx> wrote in message
news:f233d609-b206-46a0-bc5c-61f1e5050873@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 6, 10:14 pm, thinktwice <memorial...@xxxxxxxxx> wrote:
On May 7, 6:29 am, "Dean Wells \(MVP\)"
<dwe...@xxxxxxxxxxxxxxxxxxxxx>
wrote:



That's a relative path, I'd assumed it was clear I was supplying a
means
of identifying an absolute path.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

"Esra Sdrawkcab" <ad...@xxxxxxxxx> wrote in message

news:QA2Uj.109012$Ff4.33639@xxxxxxxxxxxxxxxxxxxxxxx

Dean Wells (MVP) wrote:
For validity, use an 'if exist'. To determine whether a
supplied
path is relative or absolute, verify that one of the following
is
true -

1. the second and third characters are a colon and backslash
respectively
2. the first character is a backslash

How about
..\uponefolder\siblingfolder
?

by the way , could i analyze a literal string char by char ? seems
for
loop could only process token by token

Here's one way I can think of to parse a string ...

@echo off
set "string=%~1"
set "n="
:loop
if not defined string goto :EOF
set /a n+=1
set "char=%string:~0,1%"
set "string=%string:~1%"
echo %n% %char% %string%
goto loop

I thought if I knew the length of the string, it could also be done in
a FOR /L statement, but I couldn't find a good solution to the 'find
the length' problem in a google search. So, I constructed this
one ...

@echo off
echo.|set /p "x=%1" > %temp%\tmp.txt
for %%a in (%temp%\tmp.txt) do set Length=%%~za
del %temp%\tmp.txt
echo %Length%

So with the length the FOR parsing goes something like this ...

@echo off
echo.|set /p "x=%1" > %temp%\tmp.txt
for %%a in (%temp%\tmp.txt) do set /a c=%%~za-1
del %temp%\tmp.txt
set "string=%~1"
for /l %%a in (0,1,%c%) do call echo %%a %%string:~%%a,1%%

The looping solution seems a tiny bit more useful to me, but ...

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/


.



Relevant Pages

  • Re: Question for ¬a/b
    ... if not exist %1.m goto pst1_n_as2 ... echo Uso con la shell: ... char* estrai ... int catstr ...
    (alt.lang.asm)
  • Re: How to left pad a string with spaces?
    ... How do I use sprintf to convert the string so it has 4 spaces padded on ... char* the4spaces ... ifgoto l0; ...
    (comp.lang.c)
  • a turbo assembly language
    ... if not exist %1.m goto pst1_n_as2 ... echo Uso con la shell: ... int catstr ... õ2\nmov õ1, eax"); ...
    (alt.lang.asm)
  • Re: robocopy validation
    ... Robocopy did not copy any files. ... if errorlevel 8 echo **FAILED COPIES** & goto end ...
    (microsoft.public.win2000.general)
  • Re: set user=%username%
    ... Your most recent feedback confirms that Windows is ... Type this: echo %MyName% ... > usertest=This is a long string. ...
    (microsoft.public.windows.server.general)