----- was not recognized

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

----- was not recognized

#1 Post by Elidor » 20 Mar 2013 12:27

Hello, I'm new to batch scripting and don't have any idea how to solve this problem. I'm on windows 7 and am attempting to do something like this:

Code: Select all

for %%e in (%path%) do echo %%e


Where I'm trying to cycle though each file in the path. The problem is this batch file will not work since my path has spaces giving an error like \Program Files or \Intel\iCLS was not recognized at this time.

My ultimate goal is to make this batch file run. It was an example from the book Windows 7 and Vista Guide to Scripting, Automation, and Command Line Tools.

Code: Select all

@rem                                               Example file which.bat
   @echo off

   if "%1" == "" (
       echo Usage: which command
       echo Locates the file run when you type 'command'.
       exit /b
   )

   for %%d in (. %path%) do (
       if "%~x1" == "" (
           rem the user didn't type an extension so use the PATHEXT list
           for %%e in (%pathext%) do (
               if exist %%d\%1%%e (
                   echo %%d\%1%%e
                   exit /b
               )
           )
       ) else (
           rem the user typed a specific extension, so look only for that
           if exist %%d\%1 (
               echo %%d\%1
               exit /b
           )
       )
   )
   echo No file for %1 was found


Any help would be greatly appreciated.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: ----- was not recognized

#2 Post by Squashman » 20 Mar 2013 13:00

Code: Select all

SET TempPath="%Path:;=";"%"
FOR %%a IN (%TempPath%) DO echo.%%~a

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

Re: ----- was not recognized

#3 Post by Elidor » 20 Mar 2013 13:26

Thank you so much. A very clear and straightforward solution.

Post Reply