Quotations in an if statement.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Elidor
Posts: 4
Joined: 20 Mar 2013 12:16

Quotations in an if statement.

#1 Post by Elidor » 07 Apr 2013 10:36

Hello, I'd like to know how to be able to get this program to recognize filenames with spaces. I tried changing the quotes to braces for the ifs but then I get an error at the if statement with the asterid.

Example Run:
notepad++ "SDL notes"

notepad++.bat

Code: Select all

@echo off
setlocal

if "%1" == "" (
   start notepad++.exe
   exit /b
)

:again
REM Need this since you cannot treat parameters as variables when editing
set arg=%1

if "%1" == "" exit /b

if "%arg:~0,1%" EQU "*" (
   for %%i in (%1) do start "" notepad++.exe %%i
) else (
   start "" notepad++.exe %1
)
shift
goto again

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Quotations in an if statement.

#2 Post by Endoro » 07 Apr 2013 10:49

Try this:

Code: Select all

@echo off
setlocal

if "%~1"=="" (
   start "" notepad++.exe
   exit /b
)

:again
if "%~1"=="" exit /b
for %%i in ("%~1") do start "" notepad++.exe "%%~i"
shift /1
goto:again

Elidor
Posts: 4
Joined: 20 Mar 2013 12:16

Re: Quotations in an if statement.

#3 Post by Elidor » 07 Apr 2013 15:56

Thank you very much you not only solved my problem but split the code in half. I have a lot to learn about batch.

Post Reply