Click here to Skip to main content
14,924,665 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am trying to find all the pendinglist files in my perforce depoth opened by me and if there are some pendingfiles in the pendinglist I want to execute :eof funtion, if not I want to do something

When I execute the below mentioned script. I can see the opened files printed on the console but after that the script throwing an error as "- was unexpected at this time."

What should I do to get if there are some pendingfiles in the pendinglist I want to execute :eof funtion, if not I want to do something


What I have tried:

I tried like this 

    <code>@echo off
    cls
    set P4CLIENT=<Workspace_name>
    set P4PORT=<IPadress:port>
    set P4USER=%username%
    
    set Depot_Path=//Depoth/path/...
    
    FOR /F "delims=" %%i IN ('p4 opened -u %username% //Depoth/path/...') DO set open_files=%%i
    echo %open_files%
    
    if %open_files% =="" (
        echo No file are in pendig list
        goto execute
        ) else (
            echo files are in pending list, please submit them if needed or revert them 
            echo %open_files%
            goto eof
        )
    
    :execute
    <Do something>
    :eof</code>
Posted
Updated 5-Mar-21 20:32pm

1 solution

Use double quotes in if "string" == "" () else ()
Not if string == "", or if defined var () else ()

Use double quotes in set "var=string"

At the end of each label, if you don't want the processing to proceed to the next one, use Goto: EoF

You need to use another name on the label: EOF
Cmd.exe (command interpreter) will understand: "Go To End Of File"
And stop batch commands immediately without executing any of the commands on your label: EOF

C:\Users\Shaik Izaz>Goto /?
Directs cmd.exe to a labeled line in a batch program.

GOTO label

  label   Specifies a text string used in the batch program as a label.

You type a label on a line by itself, beginning with a colon.

If Command Extensions are enabled GOTO changes as follows:

GOTO command now accepts a target label of :EOF which transfers control
to the end of the current batch script file.  This is an easy way to
exit a batch script file without defining a label.  Type CALL /?  for a
description of extensions to the CALL command that make this feature
useful.


@echo off & cls

set "Depot_Path=//Depoth/path/..."

set "P4CLIENT=<Workspace_name>"
set "P4PORT=<IPadress:port>"
set "P4USER=%username%"
    
FOR /F useback^delims^= %%i IN (`p4 opened -u "%username%" "//Depoth/path/..."`) DO set "open_files=%%~i"
echo\%open_files%
    
if "%open_files%" == "" ( 
      echo\No file are in pendig list && goto :execute 
	) else (
      echo=files are in pending list, please submit them if needed or revert them 
	  echo=%open_files% 
      goto %:^)
    )
    
    :execute
    <Do something>
	Goto :eOf
    
    %:^)
    rem :: Your :eOf commands came here
    rem :: In lable %:^)
    rem :: Rename the label for some readable..
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900