Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何在批处理脚本的for循环中使用子字符串?_Batch File_For Loop_Substring - Fatal编程技术网

Batch file 如何在批处理脚本的for循环中使用子字符串?

Batch file 如何在批处理脚本的for循环中使用子字符串?,batch-file,for-loop,substring,Batch File,For Loop,Substring,这是我的第一批脚本。我想转换文件列表并使用输入文件名(一年中的某一天)的子字符串。但是,子字符串部分不起作用: 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 RINE

这是我的第一批脚本。我想转换文件列表并使用输入文件名(一年中的某一天)的子字符串。但是,子字符串部分不起作用:

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
)

那么,我应该怎么做呢?

除了@Stephan的评论之外,我还更新了您的代码,使用一些抽象的文件路径和子字符串参数制作了一个最小工作示例(MWE)

然后我将
setlocalenabledelayedexpansion
移动到
FOR
循环中,现在它可以在Windows7上运行

我还通过
endlocal
关闭了
SETLOCAL EnableDelayedExpansion
(可能对进一步的代码执行很敏感

@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
)

您应该会收到错误消息。要在批处理文件中使用,请使用
%%G
而不是
%G
set-filInp=“%G”
应为
set-filInp=%%G” REM在STRIGOK中不起作用。我使用%%G更改批处理脚本。它现在似乎在工作。实际上我先尝试过,但是我认为我使用了%而不是!对于DOY变量。(然后,我把代码复制到CMD窗口之前,看到错误输出并使用%g,但是忘记了这一点)。谢谢!