3

This is my first batch script. I want to convert a list of files and use a substring of the input filename (Day of year). However the substring part doesn't work:

SETLOCAL EnableDelayedExpansion

FOR %G IN (%dirInp%%station%???0.DAT) DO (

SET filInp="%G"

SET doy=!filInp:~-9,3! rem this doesn't work?

rem Convert Trimble GPS receiver observations to RINEX
%dirExe%teqc -tr d %G > %dirOut%%station%!doy!0.%yy%D
)

So, how should I do this?

3
  • 1
    you should get an error message. For use in batchfile, use %%G instead of %G. set filInp="%G" should be set "filInp=%%G" Commented Feb 28, 2018 at 11:19
  • rem does not work in the middle of the string Commented Feb 28, 2018 at 12:16
  • Ok I changed the batch script using %%G it seems to work now. I actually tried that first, but there I think I used % instead of ! for the doy-variable. (And then I copied the code to the cmd-window earlier to see the error output and used %G, but forgot about that). Thank you! Commented Feb 28, 2018 at 12:21

1 Answer 1

3

In addition to @Stephan 's comment I've updated your code to make a minimal working example (MWE) using some abstact file paths and substring parameters.

Than I moved SETLOCAL EnableDelayedExpansion inside the FOR loop and now it works for me on Windows 7.

I also closed SETLOCAL EnableDelayedExpansion by endlocal (could be sensitive for further code excecution

@echo off

FOR %%G IN (C:\DirInput_StationA\201901.DAT C:\DirInput_StationB\201812.DAT) DO (
    SETLOCAL EnableDelayedExpansion
    SET "filInp=%%G"

    SET "doy=!filInp:~-10,4!"

    rem Convert Trimble GPS receiver observations to RINEX
    REM Changed your call to echo of the vars
    echo G: "%%G"; doy: "!doy!"
    endlocal
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.