Page 1 of 1

Testing if folder exist when there are spaces in a path

Posted: 17 Apr 2008 01:41
by honyk
I am using following logic, but it fails if there are spaces in INIT_DIR variable (I use nul test to avoid errors when copying):

Code: Select all

if exist %INIT_DIR%Images\nul (
  mkdir "%OUT_DIR%Images"
  xcopy /y "%INIT_DIR%Images" "%OUT_DIR%Images" >> %LOG% 2>&1
  if ERRORLEVEL 1 (
    GOTO ERROR
  )
)

When quotes are used "%INIT_DIR%Images\nul" then nothing is found...

Posted: 21 Apr 2008 15:12
by jeb
Hi honyk,

there are missing the " in the first line.

try

Code: Select all

if exist "%INIT_DIR%Images\nul" (
  mkdir "%OUT_DIR%Images"
  xcopy /y "%INIT_DIR%Images" "%OUT_DIR%Images" >> %LOG% 2>&1
  if ERRORLEVEL 1 (
    GOTO ERROR
  )
)


jeb

Posted: 23 Apr 2008 07:03
by honyk
Please see my last sentence in the original post. This solution doesn't work.

Posted: 23 Apr 2008 15:51
by jeb
Sorry I does not read and does not test it

but now ...

Code: Select all

@echo off
setlocal
set INIT_DIR=%~1

call :checkIt result "%INIT_DIR%"
echo result=%result%
goto :eof

::::::::::::::::::::::::::::
:checkIt
setlocal
set p=%~a2
(
endlocal
if "%p:~0,1%" == "d" (
  set %~1=1
) else (
  set %~1=0
)
goto :eof
)


This solution test for directories and results only with one if INIT_DIR is a directory

jeb