Search code examples
batch-filelabelgoto

Batch File System cannot find file after Loop


I am creating a batch file to open remote Computer Management console by taking User ID as input and computer name from 2nd column from file data.csv. it works fine on first attempt. When it goes back to :start label. and ask for other input. it gives error. System cannot find file ./data.csv My code is

 :start
    set /p Input="Enter User-ID:" 

    for /f "usebackq tokens=1-4 delims=," %%a in (".\data.csv") do (
       if %input% ==%%a ("cmd /c Start /B /wait compmgmt.msc –a /computer=%%b")

    )
    cls
    GOTO start

Solution

  • Good practice to use %~dp0 for paths in batch files (instead of relative paths like .) that way if the current working folder changes the file will always be located.

    So change to %~dp0data.csv